From: blipf at yahoo.com (Flbill Blipf)
Date: Wed, 07 Apr 1999 09:33:19 -0700
Subject: Tkinter and centering
Message-ID: <370B88CF.993D8847@yahoo.com>
X-UID: 1108                                                  

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.




