Python GUI Development Options
Before we start wading into the tkinter pond, let’s begin with some perspective on
Python GUI options in general. Because Python has proven to be such a good match
for GUI work, this domain has seen much activity over the years. In fact, although
tkinter is by most accounts still the most widely used GUI toolkit in the Python world,
there are a variety of ways to program user interfaces in Python today. Some are specific
to Windows or X Windows,† s o m e a r e c r o s s - p l a t f o r m s o l u t i o n s , a n d a l l h a v e f o l l o w i n g s
and strong points of their own. To be fair to all the alternatives, here is a brief inventory
of GUI toolkits available to Python programmers as I write these words:
tkinter
An open source GUI library and the continuing de facto standard for portable GUI
development in Python. Python scripts that use tkinter to build GUIs run portably
on Windows, X Windows (Unix and Linux), and Macintosh OS X, and they display
a native look-and-feel on each of these platforms today. tkinter makes it easy to
build simple and portable GUIs quickly. Moreover, it can be easily augmented with
Python code, as well as with larger extension packages such as Pmw ( a t h i r d - p a r t y
widget library); Tix (another widget library, and now a standard part of Python);
PIL (an image-processing extension); and ttk (Tk themed widgets, also now a
standard part of Python as of version 3.1). More on such extensions like these later
in this introduction.
The underlying Tk library used by tkinter is a standard in the open source world
at large and is also used by the Perl, Ruby, PHP, Common Lisp, and Tcl scripting
languages, giving it a user base that likely numbers in the millions. The Python
binding to Tk is enhanced by Python’s simple object model—Tk widgets become
customizable and embeddable objects, instead of string commands. tkinter takes
the form of a module package in Python 3.X, with nested modules that group some
of its tools by functionality (it was formerly known as module Tkinter in Python
2.X, but was renamed to follow naming conventions, and restructured to provide
a more hierarchical organization).
tkinter is mature, robust, widely used, and well documented. It includes roughly
25 basic widget types, plus various dialogs and other tools. Moreover, there is a
dedicated book on the subject, plus a large library of published tkinter and Tk
documentation. Perhaps most importantly, because it is based on a library
† In this book, “Windows” refers to the Microsoft Windows interface common on PCs, and “X Windows”
refers to the X11 interface most commonly found on Unix and Linux platforms. These two interfaces are
generally tied to the Microsoft and Unix (and Unix-like) platforms, respectively. It’s possible to run X
Windows on top of a Microsoft operating system and Windows emulators on Unix and Linux, but it’s not
common. As if to muddy the waters further, Mac OS X supports Python’s tkinter on both X Windows and
the native Aqua GUI system directly, in addition to platform-specific cocoa options (though it’s usually not
too misleading to lump OS X in with the “Unix-like” crowd).
358 | Chapter 7: Graphical User Interfaces
Do
wnload from Wow! eBook <www.wowebook.com>