Killing all windows: quit
To kill all the windows at once and end the GUI application (really, its active
mainloop call), the root window’s button runs the quit method instead. That is,
pressing the root window’s button ends the program. In general, the quit method
immediately ends the entire application and closes all its windows. It can be called
through any tkinter widget, not just through the top-level window; it’s also avail-
able on frames, buttons, and so on. See the discussion of the bind method and its
Window titles: title
As introduced in Chapter 7, top-level window widgets (Tk and Toplevel) have a
title method that lets you change the text displayed on the top border. Here, the
window title text is set to the string 'Sing...' in the pop-ups to override the default
'tk'.
Window icons: iconbitmap
The iconbitmap method changes a top-level window’s icon. It accepts an icon or
bitmap file and uses it for the window’s icon graphic when it is both minimized
and open. On Windows, pass in the name of a .ico file (this example uses one in
the current directory); it will replace the default red “Tk” icon that normally ap-
pears in the upper-lefthand corner of the window as well as in the Windows task-
bar. On other platforms, you may need to use other icon file conventions if the
icon calls in this book won’t work for you (or simply comment-out the calls alto-
gether if they cause scripts to fail); icons tend to be a platform-specific feature that
is dependent upon the underlying window manager.
Geometry management
Top-level windows are containers for other widgets, much like a standalone
Frame. Unlike frames, though, top-level window widgets are never themselves
packed (or gridded, or placed). To embed widgets, this script passes its windows
as parent arguments to label and button constructors.
It is also possible to fetch the maximum window size (the physical screen display
size, as a [width, height] tuple) with the maxsize() method, as well as set the initial
size of a window with the top-level geometry(" width x height + x + y ") method. It
is generally easier and more user-friendly to let tkinter (or your users) work out
window size for you, but display size may be used for tasks such as scaling images
(see the discussion on PyPhoto in Chapter 11 for an example).
In addition, top-level window widgets support other kinds of protocols that we will
utilize later on in this tour:
State
The iconify and withdraw top-level window object methods allow scripts to hide
and erase a window on the fly; deiconify redraws a hidden or erased window. The
state method queries or changes a window’s state; valid states passed in or re-
turned include iconic, withdrawn, zoomed (full screen on Windows: use geometry
424 | Chapter 8: A tkinter Tour, Part 1