[Tkinter] Centering a window in the screen ?

Richard Chamberlain richard_chamberlainNOriSPAM at ntlworld.com.invalid
Thu Jun 29 04:00:46 EDT 2000


Hi Jerome,

Your method works fine if you root.update() before entering the
center method. This method forces Tk to complete the geometry
calculations. It also processes all pending events on the event
queue so use it sparingly to avoid hogging system resources.

The behaviour your getting with winfo_width returning 1 is
simply that the negotiations between the window manager and
widgets hasn't completed so window size is actually still 1x1.

>> Is there a "center-window" in the Tkinter module?

Not that I know of.

>> Which functions am I to call to get the size of a window / a
widget?
winfo_width() and winfo_height are fine. There is also a
winfo_reqwidth() and winfo_reqheight(). These both return the
dimensions the widget requested - which of course may not be
exactly the same as what it finished with.

Some widgets, Photoclass and Bitmap spring to mind, have .width
() .height() functions which you can call directly.

>> What are all those winfo_* functions? Are we supposed to use
them or should we use some more user-oriented functions (such as
geometry(), configure(), etc.)?

Nobody has ever said not to use them ;-)


- By the way, what are those tuples returned by widget.configure
()?

configure() returns a dictionary of options for that widget.

>> Also, is there a Tkinter FAQ? I went on www.python.org, but
there
isn't much information on Tkinter... Where can I find some (and
if
possible in a downloadable form)?

http://www.python.org/topics/tkinter/doc.html is about as good
as it gets online.

You can download the pythonware docs by using websucker.py in
your tools directory where python is installed.

I'm considering starting a Tkinter web site (including a more
comprehensive FAQ) if anyone shows any interest.

Richard


-----------------------------------------------------------

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com




More information about the Python-list mailing list