Scheduled callbacks
Widget after, wait, and update methods
Other tools
Standard dialogs, clipboard, bind and Event, widget configuration options, custom
and modal dialogs, animation techniques
Most tkinter widgets are familiar user interface devices. Some are remarkably rich in
functionality. For instance, the Text class implements a sophisticated multiline text
widget that supports fonts, colors, and special effects and is powerful enough to im-
plement a web browser’s page display. The similarly feature-rich Canvas class provides
extensive drawing tools powerful enough for visualization and other image-processing
applications. Beyond this, tkinter extensions such as the Pmw, Tix, and ttk packages
described at the start of this chapter add even richer widgets to a GUI programmer’s
toolbox.
Python/tkinter for Tcl/Tk Converts
At the start of this chapter, I mentioned that tkinter is Python’s interface to the Tk GUI
library, originally written for the Tcl language. To help readers migrating from Tcl to
Python and to summarize some of the main topics we met in this chapter, this section
contrasts Python’s Tk interface with Tcl’s. This mapping also helps make Tk references
written for other languages more useful to Python developers.
In general terms, Tcl’s command-string view of the world differs widely from Python’s
object-based approach to programming. In terms of Tk programming, though, the
syntactic differences are fairly small. Here are some of the main distinctions in Python’s
tkinter interface:
Creation
Widgets are created as class instance objects by calling a widget class.
Masters (parents)
Parents are previously created objects that are passed to widget-class constructors.
Widget options
Options are constructor or config keyword arguments or indexed keys.
Operations
Widget operations (actions) become tkinter widget class object methods.
Callbacks
Callback handlers are any callable objects: function, method, lambda, and so on.
Extension
Widgets are extended using Python class inheritance mechanisms.
Composition
Interfaces are constructed by attaching objects, not by concatenating names.
412 | Chapter 7: Graphical User Interfaces