[Tkinter-discuss] Control position of Tkinter common dialogs?
matt.keenan at oracle.com
Wed Oct 27 11:58:21 CEST 2010
I have a similar issue, however not for common dialogs but for a custom
toplevel transient dialogs.
As you create your dialog it's dimensions are not known until all
idletasks have completed for child widgets being added to the dialog.
Now if you call top.widthdraw() before adding the children, the
dimensions of the toplevel is not calculated.
def __init__(self, parent=None, title=None):
self.parent = parent
def BuildGUI(self, master):
# Add widgets here frames etc...
w= self["width"]!=0 and self["width"] or self.winfo_width()
h= self["height"]!=0 and self["height"] or self.winfo_height()
ws,hs = self.winfo_screenwidth(),self.winfo_screenheight()
self.geometry('%dx%d+%d+%d' % (w, h, (ws/2) - (w/2), (hs/2) -
When above is called, my new toplevel is created, BuildGUI adds all the
widgets and the toplevel is displayed, however when CenterDialog is
called the toplevel jumps to new centered geometry.
Placing self.withdraw() before self.BuildGUI() and then placing
self.deiconify() after self.CenterDialog() I thought would do the trick.
But I end up with a width and height of 1 in CenterDialog(), withdraw
somehow stops calculation taking place. iconify has same effect as withdraw.
Any ideas what I am doing wrong ?
On 10/26/10 06:10 PM, python at bdurham.com wrote:
> > You can create a new toplevel window in the middle of the screen,
> then make it invisible and position the dialog windows relative to this
> new toplevel... Like this: http://paste-it.net/public/q2a5594/
> Thank you very much for your solution - that's an excellent workaround
> for me.
> Best regards,
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
More information about the Tkinter-discuss