[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1
developed for scripting languages, tkinter is also a relatively lightweight toolkit,
and as such it meshes well with a scripting language like Python.
Because of such attributes, Python’s tkinter module ships with Python as a standard
library module and is the basis of Python’s standard IDLE integrated development
environment GUI. In fact, tkinter is the only GUI toolkit that is part of Python; all
others on this list are third-party extensions. The underlying Tk library is also
shipped with Python on some platforms (including Windows, Mac OS X, and most
Linux and Unix-like systems). You can be reasonably sure that tkinter will be
present when your script runs, and you can guarantee this if needed by freezing
your GUI into a self-contained binary executable with tools like PyInstaller and
py2exe (see the Web for details).
Although tkinter is easy to use, its text and canvas widgets are powerful enough to
implement web pages, three-dimensional visualization, and animation. In addi-
tion, a variety of systems aim to provide GUI builders for Python/tkinter today,
including GUI Builder (formerly part of the Komodo IDE and relative of SpecTCL),
Rapyd-Tk, xRope, and others (though this set has historically tended to change
much over time; see http://wiki.python.org/moin/GuiProgramming or search the
Web for updates). As we will see, though, tkinter is usually so easy to code that
GUI builders are not widely used. This is especially true once we leave the realm
of the static layouts that builders typically support.

wxPython
A Python interface for the open source wxWidgets (formerly called wxWindows)
library, which is a portable GUI class framework originally written to be used from
the C++ programming language. The wxPython system is an extension module
that wraps wxWidgets 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. GUIs coded in Python with wxPython are port-
able to Windows, Unix-like platforms, and Mac OS X.
Because wxPython is based on a C++ class library, most observers consider it to
be more complex than tkinter: it provides hundreds of classes, generally requires
an object-oriented coding style, and has a design that some find reminiscent of the
MFC class library on Windows. wxPython often expects programmers to write
more code, partly because it is a more functional and thus complex system, and
partly because it inherits this mindset from its underlying C++ library.
Moreover, some of wxPython’s documentation is oriented toward C++, though
this story has been improved recently with the publication of a book dedicated to
wxPython. By contrast, tkinter is covered by one book dedicated to it, large sections
of other Python books, and an even larger library of existing literature on the un-
derlying Tk toolkit. Since the world of Python books has been remarkably dynamic
over the years, though, you should investigate the accuracy of these observations
at the time that you read these words; some books fade, while new Python books
appear on a regular basis.


Python GUI Development Options | 359
Free download pdf