tkinter popup

Eric Brunel eric.brunel at pragmadev.com
Tue Mar 27 14:03:55 CEST 2007


On Tue, 27 Mar 2007 12:05:07 +0200, Gigs_ <gigs at hi.t-com.hr> wrote:

> Hi all
>
> I cant figure out how to disable resizing of my popup window?

myPopupWindow.wm_resizable(0, 0)

It may or may not make resize controls disappear depending on your  
platform and/or window manager. But the resizing will be impossible in any  
case.

> How to put this popup window to show in the middle of my text editor?
> It is writen with Toplevel.

A bit trickier. For example (untested):

myPopupWindow.after_idle(centerPopupWindow)

with:

def centerPopupWindow():
   x, y = editorWindow.winfo_rootx(), editorWindow.winfo_rooty()
   w, h = editorWindow.winfo_width(), editorWindow.winfo_height()
   ww, hh = myPopupWindow.winfo_width(), myPopupWindow.winfo_height()
   myPopupWindow.geometry('%sx%s+%s+%s', ww, hh, x + w/2 - ww/2, y + h/2 -  
hh/2)

The after_idle trick is needed since the dimensions for the popup window  
will only be known when the window is actually displayed. In theory,  
myPopupWindow.update_idletasks() should update the display so that the  
window dimensions are known, but there are cases where it doesn't work. So  
the after_idle trick is surer.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"



More information about the Python-list mailing list