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

(yzsuai) #1

at the top of the examples package, though, make sure your PYTHONPATH system variable
is set to include the directory containing the PP4E examples root directory if you wish
to run the scripts here directly; they don’t attempt to automatically configure your
system or module import search paths.


To make this launcher bar even easier to run, drag it out to your desktop to generate a
clickable Windows shortcut (do something similar on other systems). Since this script
hardcodes command lines for running programs elsewhere in the examples tree, it is
also useful as an index to major book examples. Figure 10-17 shows what PyDemos
looks like when run on Windows, along with some of the demos it launches—PyDemos
is the vertical button bar on the right; it looks slightly different but works the same on
Linux.


Figure 10-17. PyDemos with its pop ups and a few demos


The source code that constructs this scene is listed in Example 10-30 (its first page may
differ slightly from that shown being edited in Figure 10-17 due to last minute tweaks
which engineers can’t seem to avoid). Because PyDemos doesn’t present much that’s
new in terms of GUI interface programming, though, much of it has been removed
here; again, see the examples package for the remainder.


In short, its demoButton function simply attaches a new button to the main window,
spring-loaded to spawn a Python program when pressed. To start programs, PyDemos
calls an instance of the launchmodes.PortableLauncher object we met at the end of
Chapter 5—its role as a tkinter callback handler here is why a function-call operation
is used to kick off the launched program.


The PyDemos and PyGadgets Launchers | 663
Free download pdf