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

(yzsuai) #1

Figure 8-34. demoAll_win: new Toplevel windows


The main root window of this program appears in the lower left of this screenshot; it
provides a States button that runs the report method of each demo object, producing
this sort of stdout text:


C:\...\PP4E\Gui\Tour> python demoAll_win.py
in onMove 0
in onMove 0
in onMove 1
you pressed Open
result: C:/Users/mark/Stuff/Books/4E/PP4E/dev/Examples/PP4E/Launcher.py
demoRadio Open
demoCheck 1 1 0 0 0
demoScale 1

As we learned earlier in this chapter, Toplevel windows function independently, but
they are not really independent programs. Destroying just one of the demo windows
in Figure 8-34 by clicking the X button in its upper right corner closes just that window.
But quitting any of the windows shown in Figure 8-34—by a demo window’s Quit
buttons or the main window’s X—quits them all and ends the application, because all
run in the same program process. That’s OK in some applications, but not all. To go
truly rogue we need to spawn processes, as the next section shows.


Running GUI Code Three Ways | 477
Free download pdf