-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
88 lines (72 loc) · 2.19 KB
/
Copy pathtimer.py
File metadata and controls
88 lines (72 loc) · 2.19 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# importing all the modules
import timeconversion
from tkinter import *
import json
with open('config.json', 'r') as config:
data = json.load(config)
hours = int(data['hours']); minutes = int(data['minutes']); seconds = int(data['seconds'])
# defining the starting minutes and seconds
# using a json format-->config.json to configure time
timer = timeconversion.Convert(hours, minutes, seconds)
print(timer[0])
hours = int(timer[0])
minutes = int(timer[1])
seconds = int(timer[2])
lever = True # currently inactive
# lever: an on/off switch for the program
# tkinter essentials
root = Tk()
root.title('Coundown')
root.geometry('200x20')
root.wm_attributes("-topmost", 1)
# countdown function helps to run the timer
def Countdown():
global hours, minutes, seconds
if hours == minutes == seconds == 0:
minutes = 'Time'; seconds = 'up'
label_hrs.grid_forget()
label_dot1.grid_forget()
label_dot2.grid_forget()
elif minutes == seconds == 0:
hours -= 1
minutes = seconds = 59
# function given below aids repetation of the function
root.after(1000, Countdown)
elif seconds == 0:
minutes -=1
seconds = 59
root.after(1000, Countdown)
else:
seconds -= 1
# function given below aids repetation of the function
root.after(1000, Countdown)
# code snippet within Countdown function
# to avoid single digit countdown number
if len(str(seconds)) == 1:
temp_sec = '0' + str(seconds)
else:
temp_sec = str(seconds)
if len(str(minutes)) == 1:
temp_min = '0' + str(minutes)
else:
temp_min = str(minutes)
label_hrs.config(text = hours) # work in progress
label_min.config(text = temp_min)
label_sec.config(text = temp_sec)
# main structuring
canvas_home = Canvas(root)
canvas_home.pack()
label_hrs = Label(canvas_home, text = hours)
label_hrs.grid(row = 1, column =1)
label_dot1 = Label(canvas_home, text =':')
label_dot1.grid(row = 1, column =2)
label_min = Label(canvas_home, text = minutes)
label_min.grid(row = 1, column = 3)
label_dot2 = Label(canvas_home, text = ':')
label_dot2.grid(row = 1, column = 4)
label_sec = Label(canvas_home, text = seconds)
label_sec.grid(row = 1, column = 5)
# 1st function to start the chain reaction of the code
Countdown()
# tkinter essentials
root.mainloop()