-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopwatch.py
80 lines (72 loc) · 2.3 KB
/
stopwatch.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from tkinter import *
import sys
import time
global count
count =0
class stopwatch():
def reset(self):
global count
count=1
self.t.set('00:00:00')
def start(self):
global count
count=0
self.timer()
def stop(self):
global count
count=1
def close(self):
self.root.destroy()
def timer(self):
global count
if(count==0):
self.d = str(self.t.get())
h,m,s = map(int,self.d.split(":"))
h = int(h)
m=int(m)
s= int(s)
if(s<59):
s+=1
elif(s==59):
s=0
if(m<59):
m+=1
elif(m==59):
m=0
h+=1
if(h<10):
h = str(0)+str(h)
else:
h= str(h)
if(m<10):
m = str(0)+str(m)
else:
m = str(m)
if(s<10):
s=str(0)+str(s)
else:
s=str(s)
self.d=h+":"+m+":"+s
self.t.set(self.d)
if(count==0):
self.root.after(1000,self.timer)
def __init__(self):
self.root=Tk()
self.root.title("Stop Watch")
self.root.geometry("570x200")
self.t = StringVar()
self.t.set("00:00:00")
self.lb = Label(self.root,textvariable=self.t,font=("Times 40 bold"),bg="white")
self.bt1 = Button(self.root,text="Start",command=self.start,font=("Times 12 bold"),bg=("#ACFA58"))
self.bt2 = Button(self.root,text="Stop",command=self.stop,font=("Times 12 bold"),bg=("#0101DF"))
self.bt3 = Button(self.root,text="Reset",command=self.reset,font=("Times 12 bold"),bg=("#FE642E"))
self.bt4 = Button(self.root, text="Exit", command=self.close,font=("Times 12 bold"),bg=("#FE642E"))
self.lb.place(x=160,y=10)
self.bt1.place(x=120,y=100)
self.bt2.place(x=220,y=100)
self.bt3.place(x=320,y=100)
self.bt4.place(x=420,y=100)
self.label = Label(self.root,text="",font=("Times 40 bold"))
self.root.configure(bg='white')
self.root.mainloop()
a=stopwatch()