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

(yzsuai) #1

Button(self, text='Pine', command=self.quit).pack()
Button(self, text='Sing', command=self.destroy).pack()
contentsub()


non-class usage


win = PopupWindow('popup', 'attachment')
Button(win, text='Redwood', command=win.quit).pack()
Button(win, text='Sing ', command=win.destroy).pack()
mainloop()


if name == 'main':
_selftest()


When run, the test generates the window in Figure 10-10. All generated windows get
a blue “PY” icon automatically, and intercept and verify the window manager’s upper
right corner “X” close button, thanks to the search and configuration logic they inherit
from the window module’s classes. Some of the buttons on the test windows close just
the enclosing window, some close the entire application, some erase an attached win-
dow, and others pop up a quit verification dialog. Run this on your own to see what
the examples’ buttons do, so you can correlate with the test code; quit actions are
tailored to make sense for the type of window being run.


Figure 10-10. windows-test display


We’ll use these window protocol wrappers in the next chapter’s PyClock example, and
then again later in Chapter 14 where they’ll come in handy to reduce the complexity
of the PyMailGUI program. Part of the benefit of doing OOP in Python now is that we
can forget the details later.


634 | Chapter 10: GUI Coding Techniques

Free download pdf