-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
41 lines (41 loc) · 1.37 KB
/
timer.py
File metadata and controls
41 lines (41 loc) · 1.37 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
#Import the required library
from tkinter import *
import time
#Create an instance of tkinter frame
win = Tk()
win.geometry('750x300')
win.resizable(False,False)
#Configure the background
win.config(bg='burlywood1')
#Create Entry Widgets for HH MM SS
sec = StringVar()
Entry(win, textvariable=sec, width = 2, font = 'Helvetica 14').place(x=220, y=120)
sec.set('00')
mins= StringVar()
Entry(win, textvariable = mins, width =2, font = 'Helvetica 14').place(x=180, y=120)
mins.set('00')
hrs= StringVar()
Entry(win, textvariable = hrs, width =2, font = 'Helvetica 14').place(x=142, y=120)
hrs.set('00')
#Define the function for the timer
def countdowntimer():
times = int(hrs.get())*3600+ int(mins.get())*60 + int(sec.get())
while times > -1:
minute,second = (times // 60 , times % 60)
hour =0
if minute > 60:
hour , minute = (minute // 60 , minute % 60)
sec.set(second)
mins.set(minute)
hrs.set(hour)
#Update the time
win.update()
time.sleep(1)
if(times == 0):
sec.set('00')
mins.set('00')
hrs.set('00')
times -= 1
Label(win, font =('Helvetica bold',22), text = 'Set the Timer',bg='burlywood1').place(x=105,y=70)
Button(win, text='START', bd ='2', bg = 'IndianRed1',font =('Helvetica bold',10), command = countdowntimer).place(x=167, y=165)
win.mainloop()