Skip to content

Commit 4c9c84a

Browse files
committed
update day 028 program
1 parent 3b7fabc commit 4c9c84a

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

028-day/program52.py

+40-4
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,57 @@
1313
WORK_MIN = 25
1414
SHORT_BREAK_MIN = 5
1515
LONG_BREAK_MIN = 20
16+
reps = 0
17+
timer = None
1618

1719
# ---------------------------- TIMER RESET ------------------------------- #
1820

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+
1929
# ---------------------------- TIMER MECHANISM ------------------------------- #
2030

2131
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)
2347

2448
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
2549
def count_down(count):
2650
count_min = math.floor(count/60)
2751
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}"
2856
canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")
2957
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)
3167

3268
# ---------------------------- UI SETUP ------------------------------- #
3369

@@ -49,10 +85,10 @@ def count_down(count):
4985
start_button = Button(text="Start", highlightthickness=0, bg=YELLOW, command=start_timer)
5086
start_button.grid(row=2, column=0)
5187

52-
stop_button = Button(text="Reset", highlightthickness=0, bg=YELLOW)
88+
stop_button = Button(text="Reset", highlightthickness=0, bg=YELLOW, command=reset_timer)
5389
stop_button.grid(row=2, column=2)
5490

55-
check_mark = Label(text="", fg=GREEN, bg=YELLOW)
91+
check_mark = Label(text="", fg=GREEN, bg=YELLOW )
5692
check_mark.grid(row=2, column=1)
5793

5894
window.mainloop()

0 commit comments

Comments
 (0)