Center new windows

Chad Netzer cnetzer at mail.arc.nasa.gov
Tue Mar 25 17:24:15 EST 2003


> "richard.a.charts.1" <charts at purdue.edu> wrote in message news:<Pine.SOL.4.51.0303172232390.25189 at herald.cc.purdue.edu>...
> > Hi,
> > I have a fairly quick question that I haven't been able find the answer
> > for.  When opening a new window, how can I force it to open in the center
> > of the screen?

Assuming Tkinter, something like this:

w = Tkinter.Toplevel()
vwidth = w.winfo_vrootwidth()
width = w.winfo_width()
x_string = "+%d" % ((vwidth / 2) - (width / 2))
vheight = w.winfo_vrootheight()
height = w.winfo_height()
y_string = "+%d" % ((vheight / 2) - (height / 2))
w.winfo_toplevel().wm_geometry(x_string+y_string)

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)







More information about the Python-list mailing list