6.2 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 in recent years. In fact, although Tkinter is the most
widely used GUI toolkit in Python, there is a variety of ways to
program user interfaces in Python today. Some are specific to Windows
or X Windows, some
are cross-platform solutions, and all have followings and strong
points all 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 (shipped with Python)
-
An open-source, portable GUI library, used as the de facto standard
for GUI development in Python. Tkinter makes it easy to build simple
GUIs quickly, and can be straightforwardly augmented with larger
component frameworks in Python. Python scripts that use Tkinter to
build GUIs run portably on Windows, X Windows (Unix), and Macintosh,
and display a native look-and-feel on each of these. The underlying
Tk library used by Tkinter is a standard in the open source world at
large, and is also used by the Perl and Tcl scripting languages.
- wxPython (http://wxpython.org)
-
An open-source Python interface for wxWindows -- a portable GUI
class framework originally written to be used from the C++
programming language. The wxPython system is an extension module that
wraps wxWindows classes. This library is generally considered to
excel at building sophisticated interfaces, and is probably the
second most popular Python GUI toolkit today, behind Tkinter. At this
writing, wxPython code is portable to Windows and Unix-like
platforms, but not the Macintosh. The underlying wxWindows library
best supports Windows and GTK (on Unix), but it is generally portable
to Windows, Unix-like platforms, and the Macintosh.
- JPython (http://www.jython.org)
-
As we will see in Chapter 15, JPython (a.k.a.
"Jython") is a Python port for Java, which gives Python
scripts seamless access to Java class libraries on the local machine.
Because of that, Java GUI libraries such as swing
and awt become another way to construct GUIs in
Python code run by the JPython system. Such solutions are obviously
Java-specific, and limited in portability to the portability of Java
and its libraries. A new package named jTkinter
also provides a Tkinter port to JPython using Java's JNI; if
installed, Python scripts may also use Tkinter to build GUIs under
JPython.
- KDE and Qt (http://www.thekompany.com/projects/pykde)
- Gnome and GTK (ftp://ftp.daa.com.au/pub/james/python)
-
On Linux, developers can find Python interfaces to the underlying GUI
libraries at the core of the KDE and Gnome window systems. The PyKDE
and PyQt extension packages provide access to KDE development
libraries (PyKDE requires PyQt). The gnome-python and PyGTK extension
packages export Gnome and GTK toolkit calls for use in Python scripts
(gnome-python requires PyGTK). Both of these sets of extensions are
as portable as the underlying libraries they use. Today, the Qt class
library runs on Unix and Windows, KDE runs on Linux and Unix
platforms, and GTK and Gnome run on Linux and Unix platforms (though
a Windows port of GTK is in the works). See relevant web sites for
more recent details.
- MFC (http://www.python.org/windows)
-
The Windows win32all.exe extensions package for
Python, available at Python's web site and on this book's
CD-ROM, includes wrappers for the Microsoft Foundation Classes (MFC)
framework -- a development library that includes user interface
components. With the Windows extensions, Python programs can
construct Windows GUIs using the same MFC calls applied in languages
such as Visual C++. Pythonwin, an MFC sample program that implements
a Python development GUI, is included with the extensions package.
This is a Windows-only solution, but may be an appealing option for
developers with a prior intellectual investment in using the MFC
framework from Visual C++.
- WPY (http://www.python.org/ftp/python/wpy)
-
An MFC-like GUI library for Python, ported to run on both X Windows
for Unix (where it uses Tk) and Windows for PCs (where it uses MFC).
WPY scripts run unchanged on each platform, but use MFC coding
styles.
- X11 (http://www.cwi.nl/ftp/sjoerd/index.html)
-
Interfaces to the raw X Windows and Motif libraries also exist for
Python. They provide maximum control over the X11 development
environment, but are an X-only solution.
There are other lesser-known GUI toolkits for Python, and new ones
are likely to emerge by the time you read this book (e.g., the newly
announced Python port to the .NET framework on Windows may offer user
interface options as well). Moreover, package and web site names like those
in this list mutate over time. For an up-to-date list of available
tools, see http://www.python.org and the new
"Vaults of Parnassus" third-party packages site currently
at http://www.vex.net/parnassus.
|