[Tkinter-discuss] Control position of Tkinter common dialogs?
Matt Keenan
matt.keenan at oracle.com
Wed Oct 27 11:58:21 CEST 2010
Hi,
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.
e.g.
class MyDialog(TopLevel):
def __init__(self, parent=None, title=None):
TopLevel.__init__(self, parent)
self.title(title)
self.parent = parent
self.BuildGUI(master=self)
self.CenterDialog()
self.transient(parent)
def BuildGUI(self, master):
# Add widgets here frames etc...
pass
def CenterDialog(self):
self.update_idletasks()
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) -
(h/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 ?
thanks
Matt
On 10/26/10 06:10 PM, python at bdurham.com wrote:
> Firat,
> > 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,
> Malcolm
>
>
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
More information about the Tkinter-discuss
mailing list