def init(self, app, kind='', iconfile=None):
Tk.init(self)
self.__app = app
self.configBorders(app, kind, iconfile)
def quit(self):
if self.okayToQuit(): # threads running?
if askyesno(self.app, 'Verify Quit Program?'):
self.destroy() # quit whole app
else:
showinfo(self.app, 'Quit not allowed') # or in okayToQuit?
def destroy(self): # exit app silently
Tk.quit(self) # redef if exit ops
def okayToQuit(self): # redef me if used
return True # e.g., thread busy
class PopupWindow(Toplevel, _window):
"""
when run in secondary pop-up window
"""
def init(self, app, kind='', iconfile=None):
Toplevel.init(self)
self.__app = app
self.configBorders(app, kind, iconfile)
def quit(self): # redef me to change
if askyesno(self.__app, 'Verify Quit Window?'): # or call destroy
self.destroy() # quit this window
def destroy(self): # close win silently
Toplevel.destroy(self) # redef for close ops
class QuietPopupWindow(PopupWindow):
def quit(self):
self.destroy() # don't verify close
class ComponentWindow(Frame):
"""
when attached to another display
"""
def init(self, parent): # if not a frame
Frame.init(self, parent) # provide container
self.pack(expand=YES, fill=BOTH)
self.config(relief=RIDGE, border=2) # reconfig to change
def quit(self):
showinfo('Quit', 'Not supported in attachment mode')
destroy from Frame: erase frame silent # redef for close ops
So why not just set an application’s icon and title by calling protocol methods directly?
For one thing, those are the sorts of details that are easy to forget (you will probably
wind up cutting and pasting code much of the time). For another, these classes add
632 | Chapter 10: GUI Coding Techniques