13
13
WORK_MIN = 25
14
14
SHORT_BREAK_MIN = 5
15
15
LONG_BREAK_MIN = 20
16
+ reps = 0
17
+ timer = None
16
18
17
19
# ---------------------------- TIMER RESET ------------------------------- #
18
20
21
+ def reset_timer ():
22
+ window .after_cancel (timer )
23
+ canvas .itemconfig (timer_text , text = "00:00" )
24
+ timer_label .config (text = "Timer" )
25
+ check_mark .config (text = "" )
26
+ global reps
27
+ reps = 0
28
+
19
29
# ---------------------------- TIMER MECHANISM ------------------------------- #
20
30
21
31
def start_timer ():
22
- count_down (5 * 60 )
32
+ global reps
33
+ reps += 1
34
+ work_sec = WORK_MIN * 60
35
+ short_break_sec = SHORT_BREAK_MIN * 60
36
+ long_break_sec = LONG_BREAK_MIN * 60
37
+
38
+ if reps % 8 == 0 :
39
+ count_down (long_break_sec )
40
+ timer_label .config (text = "Break" , fg = RED )
41
+ elif reps % 2 == 0 :
42
+ count_down (short_break_sec )
43
+ timer_label .config (text = "Break" , fg = PINK )
44
+ else :
45
+ count_down (work_sec )
46
+ timer_label .config (text = "Work" , fg = GREEN )
23
47
24
48
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
25
49
def count_down (count ):
26
50
count_min = math .floor (count / 60 )
27
51
count_sec = count % 60
52
+ if count_sec < 10 :
53
+ #Here we use the dynamic type. Python allow to set a varaible/ assign a variable different type
54
+ #So we can say python is strongly a `Dynamic Type` language
55
+ count_sec = f"0{ count_sec } "
28
56
canvas .itemconfig (timer_text , text = f"{ count_min } :{ count_sec } " )
29
57
if count > 0 :
30
- window .after (1000 , count_down , count - 1 )
58
+ global timer
59
+ timer = window .after (1000 , count_down , count - 1 )
60
+ else :
61
+ start_timer ()
62
+ marks = ""
63
+ work_seessions = math .floor (reps / 2 )
64
+ for _ in range (work_seessions ):
65
+ marks += "✓"
66
+ check_mark .config (text = marks )
31
67
32
68
# ---------------------------- UI SETUP ------------------------------- #
33
69
@@ -49,10 +85,10 @@ def count_down(count):
49
85
start_button = Button (text = "Start" , highlightthickness = 0 , bg = YELLOW , command = start_timer )
50
86
start_button .grid (row = 2 , column = 0 )
51
87
52
- stop_button = Button (text = "Reset" , highlightthickness = 0 , bg = YELLOW )
88
+ stop_button = Button (text = "Reset" , highlightthickness = 0 , bg = YELLOW , command = reset_timer )
53
89
stop_button .grid (row = 2 , column = 2 )
54
90
55
- check_mark = Label (text = "✓ " , fg = GREEN , bg = YELLOW )
91
+ check_mark = Label (text = "" , fg = GREEN , bg = YELLOW )
56
92
check_mark .grid (row = 2 , column = 1 )
57
93
58
94
window .mainloop ()
0 commit comments