self.display = self.analogDisplay self.display.pack(side=TOP, expand=YES, fill=BOTH)
def onToggleLabel(self, event): self.labelOn += 1 if self.labelOn % 2:
self.dateLabel.pack(side=BOTTOM, fill=X) else:
self.dateLabel.pack_forget()
self.update()
def onResize(self, event):
if event.widget == self.display:
self.display.onResize(event.width, event.height, self.cfg)
def onTimer(self):
secsSinceEpoch = time.time() timeTuple = time.localtime(secsSinceEpoch) hour, min, sec = timeTuple[3:6] if sec != self.lastSec: self.lastSec = sec
ampm = ((hour >= 12) and ‘PM’) or ‘AM’ # 0...23
hour = (hour % 12) or 12 # 12..11
self.display.onUpdate(hour, min, sec, ampm, self.cfg) self.dateLabel.config(text=time.ctime(secsSinceEpoch)) self.countdownSeconds -= 1 if self.countdownSeconds == 0:
self.onCountdownExpire() # таймер обратного отсчета
self.after(1000 // ChecksPerSec, self.onTimer) # вызывать N раз в сек.
# 3.x // целочисленное
# деление с усечением
def onCountdownSec(self, event):
secs = askinteger(‘Countdown’, ‘Seconds?’) if secs: self.countdownSeconds = secs
def onCountdownMin(self, event):
secs = askinteger(‘Countdown’, ‘Minutes’) if secs: self.countdownSeconds = secs * 60
def onCountdownExpire(self):
# ВНИМАНИЕ: только один активный таймер,
# текущее состояние таймера не отображается win = Toplevel()
msg = Button(win, text=’Timer Expired!’, command=win.destroy) msg.config(font=(‘courier’, 80, ‘normal’), fg=’white’, bg=’navy’) msg.config(padx=10, pady=10) msg.pack(expand=YES, fill=BOTH)
win.lift() # поднять над другими окнами
if sys.platform[:3] == ‘win’: # в Windows - на полный экран win.state(‘zoomed’)
##############################################################################
# Автономные часы
##############################################################################