Tkinter and centering
Flbill Blipf
blipf at yahoo.com
Wed Apr 7 12:33:19 EDT 1999
Hi,
How do I center a window with Tkinter? If I use this:
from Tkinter import *
root = Tk()
Label(root,text="Cough Cough Cough").pack()
root.update()
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
w = root.winfo_width()
h = root.winfo_height()
newGeometry='+%d+%d' % ((sw/2)-(w/2), (sh/2)-(h/2))
root.geometry(newGeometry=newGeometry)
root.mainloop()
The window appears in a semi-random location and then staggers to the
center.
If I remove root.update(), winfo_width and winfo_height both return 1.
More information about the Python-list
mailing list