tkinter Overview
Of all the prior section’s GUI options, though, tkinter is by far the de facto standard
way to implement portable user interfaces in Python today, and the focus of this part
of the book. The rationale for this approach was explained in Chapter 1; in short, we
elected to present one toolkit in satisfying depth instead of many toolkits in less-than-
useful fashion. Moreover, most of the tkinter programming concepts you learn here
will translate directly to any other GUI toolkit you choose to utilize.
tkinter Pragmatics
Perhaps more to the point, though, there are pragmatic reasons that the Python world
still gravitates to tkinter as its de facto standard portable GUI toolkit. Among them,
tkinter’s accessibility, portability, availability, documentation, and extensions have
made it the most widely used Python GUI solution for many years running:
Accessibility
tkinter is generally regarded as a lightweight toolkit and one of the simplest GUI
solutions for Python available today. Unlike larger frameworks, it is easy to get
started in tkinter right away, without first having to grasp a much larger class in-
teraction model. As we’ll see, programmers can create simple tkinter GUIs in a few
lines of Python code and scale up to writing industrial-strength GUIs gradually.
Although the tkinter API is basic, additional widgets can be coded in Python or
obtained in extension packages such as Pmw, Tix, and ttk.
Portability
A Python script that builds a GUI with tkinter will run without source code changes
on all major windowing platforms today: Microsoft Windows, X Windows (on
Unix and Linux), and the Macintosh OS X (and also ran on Mac classics). Further,
that same script will provide a native look-and-feel to its users on each of these
platforms. In fact, this feature became more apparent as Tk matured. A Python/
tkinter script today looks like a Windows program on Windows; on Unix and
Linux, it provides the same interaction but sports an appearance familiar to X
Windows users; and on the Mac, it looks like a Mac program should.
Availability
tkinter is a standard module in the Python library, shipped with the interpreter. If
you have Python, you have tkinter. Moreover, most Python installation packages
(including the standard Python self-installer for Windows, that provided on Mac
OS X, and many Linux distributions) come with tkinter support bundled. Because
of that, scripts written to use the tkinter module work immediately on most Python
interpreters, without any extra installation steps. tkinter is also generally better
supported than its alternatives today. Because the underlying Tk library is also used
by the Tcl and Perl programming languages (and others), it tends to receive more
development resources than other toolkits available.
tkinter Overview | 363