-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrono.py
More file actions
executable file
·58 lines (47 loc) · 1.74 KB
/
chrono.py
File metadata and controls
executable file
·58 lines (47 loc) · 1.74 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
from Tkinter import Tk, Label, Frame, Button, StringVar
from Tkinter import TOP, BOTTOM, LEFT, RIGHT, X
from time import gmtime, strftime
class Chrono():
def __init__(self, master):
self.master = master
self.t0 = 0.
self.time = StringVar()
self.time.set(strftime("%H:%M:%S", gmtime(self.t0)))
self.flag = 0
self.affichageChrono = Frame(self.master)
self.affichageChrono.pack(side=TOP, fill=X)
self.chrono = Label(self.affichageChrono, textvariable=self.time)
self.chrono.pack(side=TOP)
self.affichageBoutons = Frame(self.master)
self.affichageBoutons.pack(side=BOTTOM, fill=X)
self.boutonStart = Button(self.affichageBoutons, text="Start",
command=self.action)
self.boutonStart.pack(side=LEFT)
self.boutonStop = Button(self.affichageBoutons, text="Stop",
command=self.stop)
self.boutonStop.pack(side=LEFT)
self.boutonReset = Button(self.affichageBoutons, text="Reset",
command=self.reset)
self.boutonReset.pack(side=LEFT)
self.boutonExit = Button(self.affichageBoutons, text="Exit",
command=self.master.quit)
self.boutonExit.pack(side=RIGHT)
def action(self):
self.flag = 1
self.start()
def start(self):
self.time.set(strftime("%H:%M:%S", gmtime(self.t0)))
if self.flag == 0:
return
self.t0 += 1.
self.master.after(1000, self.start)
def stop(self):
self.flag = 0
def reset(self):
self.t0 = 0.
self.time.set(strftime("%H:%M:%S", gmtime(self.t0)))
if __name__ == "__main__":
root = Tk()
chro = Chrono(root)
root.mainloop()