class ClockWindow(Clock):
def init(self, config=ClockConfig, parent=None, name=''):
Clock.init(self, config, parent)
self.pack(expand=YES, fill=BOTH)
title = appname
if name: title = appname + ' - ' + name
self.master.title(title) # master=parent or default
self.master.protocol('WM_DELETE_WINDOW', self.quit)
###############################################################################
Program run
###############################################################################
if name == 'main':
def getOptions(config, argv):
for attr in dir(ClockConfig): # fill default config obj,
try: # from "-attr val" cmd args
ix = argv.index('-' + attr) # will skip x internals
except:
continue
else:
if ix in range(1, len(argv)-1):
if type(getattr(ClockConfig, attr)) == int:
setattr(config, attr, int(argv[ix+1]))
else:
setattr(config, attr, argv[ix+1])
#config = PhotoClockConfig()
config = ClockConfig()
if len(sys.argv) >= 2:
getOptions(config, sys.argv) # clock.py -size n -bg 'blue'...
#myclock = ClockWindow(config, Tk()) # parent is Tk root if standalone
#myclock = ClockPopup(ClockConfig(), 'popup')
myclock = ClockMain(config)
myclock.mainloop()
And finally, Example 11-13 shows the module that is actually run from the PyDemos
launcher script—it predefines a handful of clock styles and runs seven of them at once,
attached to new top-level windows for a demo effect (though one clock per screen is
usually enough in practice, even for me!).
Example 11-13. PP4E\Gui\Clock\clockStyles.py
precoded clock configuration styles
from clock import *
from tkinter import mainloop
gifdir = '../gifs/'
if name == 'main':
from sys import argv
if len(argv) > 1:
gifdir = argv[1] + '/'
760 | Chapter 11: Complete GUI Programs