Skip to content

Commit b40033d

Browse files
Merge pull request avinashkranjan#801 from aishwaryachand/stopwatch
Stopwatch GUI
2 parents e673ab3 + 8acccdf commit b40033d

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

Stopwatch GUI/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Stopwatch GUI
2+
3+
This is a Stopwatch GUI using which user can measure the time elapsed using the start and pause button. User can also use the reset button to reset the stopwatch and exit button to close the window.
4+
5+
## Dependencies
6+
You will use `Tkinter` and `time` python module .
7+
8+
## Sample Output
9+
On running `Stopwatch_gui.py`.
10+
11+
[![stopwatch-gui1.png](https://i.postimg.cc/2yYGVSY0/stopwatch-gui1.png)](https://postimg.cc/1nWwdPfF)
12+
13+
### After using Start button
14+
[![Capture.png](https://i.postimg.cc/76gbwzLD/Capture.png)](https://postimg.cc/S2xmGJ8t)
15+
16+
## Author
17+
[Aishwarya Chand](https://github.com/aishwaryachand)

Stopwatch GUI/stopwatch1.png

14.6 KB
Loading

Stopwatch GUI/stopwatch2.png

18.8 KB
Loading

Stopwatch GUI/stopwatch_gui.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import tkinter as tk
2+
import tkinter.font as TkFont
3+
from datetime import datetime
4+
5+
def timer():
6+
global work
7+
if work:
8+
now = str(txt_var.get())
9+
m,s = map(int, now.split(":"))
10+
m=int(m)
11+
s= int(s)
12+
if(s<59):
13+
s+=1
14+
elif(s==59):
15+
s=0
16+
if(m<59):
17+
m+=1
18+
elif(m==59):
19+
m=0
20+
if(m<10):
21+
m = str(0)+str(m)
22+
else:
23+
m = str(m)
24+
if(s<10):
25+
s=str(0)+str(s)
26+
else:
27+
s=str(s)
28+
now =m+":"+s
29+
30+
txt_var.set(now)
31+
if work:
32+
root.after(1000,timer)
33+
#start function
34+
def start():
35+
global work
36+
if not work:
37+
work = True
38+
timer()
39+
40+
#stop function
41+
def pause():
42+
global work
43+
work = False
44+
45+
#reset function
46+
def reset():
47+
global work
48+
if not work:
49+
txt_var.set('0:00')
50+
51+
52+
if __name__ == "__main__" :
53+
work = False
54+
55+
root = tk.Tk()
56+
root.geometry("500x221") #width x height
57+
root.title("My StopWatch")
58+
59+
txt_var = tk.StringVar()
60+
txt_var.set('0:00')#initial display of string
61+
root.config(background = "lavender")
62+
63+
fontstyle = TkFont.Font(family ="Helvetica",size = 60,)
64+
tk.Label(root,textvariable=txt_var,font=fontstyle,).pack()
65+
66+
#creating the buttons for start,stop and reset
67+
T=tk.Text(root ,height =0.7 ,width = 9)
68+
T.pack()
69+
T.insert(tk.END," mm : ss ")
70+
tk.Button(root,text = "Start",command=start,bg ='misty rose').pack(fill = 'x')
71+
tk.Button(root,text='Pause',command = pause,bg ='misty rose').pack(fill='x')
72+
tk.Button(root,text = 'Reset',command = reset,bg ='misty rose').pack(fill='x')
73+
tk.Button(root,text = 'Exit',command = root.destroy,bg ='misty rose').pack(fill='x')
74+
root.mainloop()

0 commit comments

Comments
 (0)