tkinter popup

G

Gigs_

Hi all

I cant figure out how to disable resizing of my popup window?
How to put this popup window to show in the middle of my text editor?
It is writen with Toplevel.


thx
 
E

Eric Brunel

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
 
G

Gigs_

Eric said:
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+-'])"

thanks for both replay, they are very helpful. specially this one, it
will took some times for me to figure this. i was completely forgot that
this can be done like that

thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top