Skip to content Skip to sidebar Skip to footer

Centering A Tkinter Toplevel Window In Both Windows And Remote X11?

I know Tkinter can be an exercise in frustration at times, but I am stumped on the 'correct' sequence of calls to a Tkinter/ttk Toplevel widget/window that will: Display the windo

Solution 1:

Solved! Had to tweak the order of the calls a little bit:

#// Done!
self.withdraw()
self.grid()
self.transient(self._parent)
self.grab_set()
self.form.initial_focus()
center(self)
self.deiconify()
self._parent._parent.wait_window(self)

But the real fix was in the center() function I lifted from this answer, by changing the calls to winfo_width()/winfo_height() to winfo_reqwidth()/winfo_reqheight() and adding a call to update() as the first call in center(). Now I get my dialog windows to pop up in the center without seeing them move, focus is applied correctly, and it works on both Windows and remote X11. Maybe one day, I'll find out how well it works on Mac OS X/Aqua.


Post a Comment for "Centering A Tkinter Toplevel Window In Both Windows And Remote X11?"