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

(yzsuai) #1

larger GUI examples coming up, with a quick look at scripts that launch them auto-
matically, and allow you to sample some of what is possible with Python and tkinter.


The PyDemos and PyGadgets Launchers


To close out this chapter, let’s explore the implementations of the two GUIs used to
run major book examples. The following GUIs, PyDemos and PyGadgets, are simply
GUIs for launching other GUI programs. In fact, we’ve now come to the end of the
demo launcher story—both of the new programs here interact with modules that we
met earlier in Part II:


launchmodes.py
Starts independent Python programs portably.


Launcher.py
Finds programs, and ultimately runs both PyDemos and PyGadgets when used by
the self-configuring top-level launcher scripts.


LaunchBrowser.pyw
Spawns web browsers portably to open local or remote pages.


See Part II (especially the ends of Chapter 5 and Chapter 6) for links to the code for
these modules. The programs introduced here add the GUI components to the
program-launching system—they simply provide easy-to-use pushbuttons that spawn
most of the larger examples in this text when pressed.


Both of these scripts also assume that they will be run with the current working directory
set to their directory (they hardcode paths to other programs relative to that). Either
click on their names in a file explorer or run them from a command-line shell after a
cd to the top-level PP4E examples root directory. These scripts could allow invocations
from other directories by prepending an environment variable’s value to program script
paths, but they were really designed to be run only out of the PP4E root.


Because these demo launchers are long programs, in the interest of space and time only
their crucial and representative parts are listed in this book; as usual, see the examples
package distribution for the portions omitted here.


PyDemos Launcher Bar (Mostly External)


The PyDemos script constructs a bar of buttons that run programs in demonstration
mode, not for day-to-day use. I use PyDemos to show off Python programs—it’s much
easier to press its buttons than to run command lines or fish through a file explorer
GUI to find scripts.


You can use PyDemos (and PyGadgets) to start and interact with examples presented
in this book—all of the buttons on this GUI represent examples we will meet in later
chapters. Unlike when using the Launch_PyDemos and Launch_PyGadgets_bar scripts


662 | Chapter 10: GUI Coding Techniques

Free download pdf