1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import Tkinter
class Chrono(Tkinter.Label):
def __init__(self, root, startTime=0):
Tkinter.Label.__init__(self, root, text='Starting...')
self.value = startTime
self.font = ('Helvetica', 36, 'normal')
self.__setitem__('font',self.font)
self.after(1000, self.count)
self.stopchrono = False
def formatTime(self):
return str(self.value/60)+': '+str(self.value%60)
def count(self):
if not self.stopchrono:
self.value += 1
self.__setitem__('text', self.formatTime())
self.after(1000,self.count)
def stop(self):
self.stopchrono = True
def start(self):
self.stopchrono = False
self.count()
def declenche_chrono():
root = Tkinter.Tk()
root.title('Chrono')
label = Chrono(root, 0)
label.pack()
Tkinter.Button(root, text="Stop", command=label.stop).pack()
Tkinter.Button(root, text="Start", command=label.start).pack()
root.mainloop()
declenche_chrono() |
Partager