Repository navigation
Expand file tree
/
Copy pathtimerwithgui.py
More file actions
66 lines (50 loc) · 2.01 KB
/
Copy pathtimerwithgui.py
File metadata and controls
66 lines (50 loc) · 2.01 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
59
60
61
62
63
64
65
66
import time, datetime
from playsound import playsound
from tkinter import *
x = [input("One by one, hour, min, sec. ") for i in range(3)]
root = Tk()
root.geometry("960x540")
root.title("Time Counter")
root.configure(bg='black')
tim = StringVar(); hour = StringVar(); minute = StringVar(); second = StringVar(); text = StringVar(); temp = 0
hour.set(int(x[0]))
minute.set(int(x[1]))
second.set(int(x[2]))
tim.set("")
text.set("H/M/S")
display = Label(root,font=("Arial",80,"bold"), fg = "white", bg = "black", textvariable=text)
display.pack(anchor = "w", side = TOP)
hours= Label(root, font=("Arial ",100,"bold"), fg = "white", bg = "black", textvariable=hour)
hours.pack(side=LEFT)
minutes= Label(root, font=("Arial ",100,"bold"), fg = "white", bg = "black", textvariable=minute)
minutes.pack(side=LEFT)
seconds= Label(root, font=("Arial ",100,"bold"), fg = "white", bg = "black", textvariable=second)
seconds.pack(side=LEFT)
timern = Label(root, font=("Arial ", 12, "bold"), fg = "white", bg = "black", textvariable=tim)
timern.pack( anchor = "e", side = BOTTOM)
def poop():
try:
temp = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
except:
print("Please input the right value")
while temp >-1:
timee = datetime.datetime.now().strftime('%H:%M:%S %p')
mins,secs = divmod(temp,60)
hours=0
if mins >60:
hours, mins = divmod(mins, 60)
text.set("Time Left:")
hour.set("{0:2d}H".format(hours))
minute.set("{0:2d}M".format(mins))
second.set("{0:2d}S".format(secs))
tim.set(f"Current time: {timee}")
root.update()
time.sleep(1)
if (temp == 0):
messagebox.showinfo("Time Countdown", "Time's up ")
root.quit()
temp -= 1
btn = Button(root, text='Start Countdown',bd = 2, fg = "white", bg="black" ,command= poop)
btn.place(x = 850,y = 450)
root.bind("x", quit)
root.mainloop()