Running the Examples
One other point I’d like to make right away: most GUIs are dynamic and interactive
interfaces, and the best I can do here is show static screenshots representing selected
states in the interactions such programs implement. This really won’t do justice to most
examples. If you are not working along with the examples already, I encourage you to
run the GUI examples in this and later chapters on your own.
On Windows, the standard Python install comes with tkinter support built in, so all
these examples should work immediately. Mac OS X comes bundled with a tkinter-
aware Python as well. For other systems, Pythons with tkinter support are either pro-
vided with the system itself or are readily available (see the top-level
README-PP4E.txt file in the book examples distribution for more details). Getting
tkinter to work on your computer is worth whatever extra install details you may need
to absorb, though; experimenting with these programs is a great way to learn about
both GUI programming and Python itself.
Also see the description of book example portability in general in this book’s Preface.
Although Python and tkinter are both largely platform neutral, you may run into some
minor platform-specific issues if you try to run this book’s examples on platforms other
than that used to develop this book. Mac OS X, for example, might pose subtle differ-
ences in some of the examples’ operation. Be sure to watch this book’s website for
pointers and possible future patches for using the examples on other platforms.
Has Anyone Noticed That G-U-I Are the First Three Letters of “GUIDO”?
Python creator Guido van Rossum didn’t originally set out to build a GUI development
tool, but Python’s ease of use and rapid turnaround have made this one of its primary
roles. From an implementation perspective, GUIs in Python are really just instances of
C extensions, and extensibility was one of the main ideas behind Python. When a script
builds push buttons and menus, it ultimately talks to a C library; and when a script
responds to a user event, a C library ultimately talks back to Python. It’s really just an
example of what is possible when Python is used to script external libraries.
But from a practical point of view, GUIs are a critical part of modern systems and an
ideal domain for a tool like Python. As we’ll see, Python’s simple syntax and object-
oriented flavor blend well with the GUI model—it’s natural to represent each device
drawn on a screen as a Python class. Moreover, Python’s quick turnaround lets pro-
grammers experiment with alternative layouts and behavior rapidly, in ways not pos-
sible with traditional development techniques. In fact, you can usually make a change
to a Python-based GUI and observe its effects in a matter of seconds. Don’t try this with
C++!
“Here’s Looking at You, Kid” | 357