if self.hellos % 3:
print("hi")
else:
self.infobox("Three", 'HELLO!') # on every third press
def dialog(self):
button = self.question('OOPS!',
'You typed "rm*" ... continue?', # old style
'questhead', ('yes', 'no')) # args ignored
[lambda: None, self.quit][button]()
def fileOpen(self):
pick = self.selectOpenFile(file='big_gui.py')
if pick:
self.browser(pick) # browse my source file, or other
def more(self):
new = Toplevel()
Label(new, text='A new non-modal window').pack()
Button(new, text='Quit', command=self.quit).pack(side=LEFT)
Button(new, text='More', command=self.more).pack(side=RIGHT)
def pickDemo(self):
pick = self.selectOpenFile(dir='..')
if pick:
self.spawn(pick) # spawn any Python program
if name == 'main': Hello().mainloop() # make one, run one
This script lays out a fairly large menu and toolbar structure, and also adds callback
methods of its own that print stdout messages, pop up text file browsers and new
windows, and run other programs. Many of the callbacks don’t do much more than
run the notDone method inherited from GuiMixin, though; this code is intended mostly
as a GuiMaker and GuiMixin demo.
When big_gui is run as a top-level program, it creates a window with four menu pull
downs on top and a three-button toolbar on the bottom, shown in Figure 10-3 along
with some of the pop-up windows its callbacks create. The menus have separators,
disabled entries, and cascading submenus, all as defined by the menuBar template used
by GuiMaker, and Quit invokes the verifying dialog inherited from GuiMixin—some of
the many tools we’re getting for free here.
Figure 10-4 shows this script’s window again, after its Play pull down has been used to
launch three independently running demos that we wrote in Chapters 8 and 9. These
demos are ultimately started by using the portable launcher tools we wrote in Chap-
ter 5 , and acquired from the GuiMixin class. If you want to run other demos on your
computer, select the Play menu’s Other option to pop up a standard file selection dialog
instead and navigate to the desired program’s file. One note: I copied the icon bitmap
used by the top-levels demo in the Play menu to this script’s directory; later, we’ll write
tools that attempt to locate one automatically.
GuiMaker: Automating Menus and Toolbars | 611