Tkinter: centering windows on screen

Kilian Lorenz kilian.lorenz at dkfz-heidelberg.de
Sun Apr 9 14:06:31 EDT 2000


Kevin Cazabon wrote:
> 
> I'm having a bit of a problem controlling where on screen a Toplevel() or
> Tk() widget appears on the screen...
> 
> I have some large widgets that sometimes appear partially off-screen, and I
> want to make sure that (at least) they're centered.
>

I have a similar problem ... I would like to call the tk_getOpenFile
Standard Dialog that is provided by Tk but I don't know how to do it.
If I use it as an option for a widget like this

self.filemenu.add_command(label='Open', command='tk_getOpenFile')

that works but doesn't help me much because I'm interested in the
return value. So I would really like to know how to call Tk commands
from
within Python because that would solve both our problems ...you could
send a Tk command like 'wm geometry <kevins enormous widget>' to receive
an return value like this: '200x200+400+300' and you could change the
position just by sending 'wm geometry <kevins enormous widget> +20+30'
to move it to somewhere near the left, upper corner. 

In the meantime I found out that exactly this can be done with Tkinter
with the wm_geometry() method.

Regards, Kilian



More information about the Python-list mailing list