-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
114 lines (96 loc) · 3.06 KB
/
main.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from tkinter import *
from playsound import playsound
# ---------------------------- CONSTANTS ------------------------------- #
PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
WORK_SEC = 1500
SHORT_BREAK_SEC = 300
LONG_BREAK_SEC = 1200
current_time = 0
reps = 1
do_continue = True
timer2 = None
# ---------------------------- START AND STOP MECHANISM ------------------ #
def start_timer():
global do_continue
do_continue = True
start_command()
def stop_timer():
global do_continue
do_continue = False
# ---------------------------- TIMER RESET ------------------------------- #
def reset_timer():
window.after_cancel(timer2)
canvas.itemconfig(timer_text, text="00:00")
timer.config(text="Timer", fg=GREEN)
check_marks.config(text="")
# ---------------------------- TIMER MECHANISM --------------------------- #
def start_command():
global reps
if do_continue:
if current_time != 0:
count_down(current_time)
else:
if reps % 2 != 0:
timer.configure(text='Work', fg=RED)
reps += 1
count_down(WORK_SEC)
elif reps % 2 == 0 and reps % 8 != 0:
timer.configure(text='Short Break', fg=PINK)
reps += 1
count_down(SHORT_BREAK_SEC)
elif reps % 8 == 0:
timer.configure(text='Long Break', fg=GREEN)
reps += 1
count_down(LONG_BREAK_SEC)
else:
reps -= 1
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def count_down(count):
global reps, current_time, timer2
if do_continue:
count_min = count // 60
count_sec = count % 60
if count_sec < 10 and count_sec >= 0:
count_sec = f'0{count_sec}'
canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")
if count > 0:
current_time = count-1
timer2 = window.after(1000, count_down, count - 1)
else:
playsound('Alarm.mp3')
start_timer()
marks = ""
for i in range(reps//2):
marks += "✔"
check_marks.config(text=marks)
elif do_continue == False:
reps -= 1
# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title('Pomodoro')
window.config(padx=100, pady=50, bg=YELLOW)
#Timer Label
timer=Label(text='Timer')
timer.configure(bg=YELLOW, fg=GREEN, font=(FONT_NAME, 40))
timer.grid(column=1, row=0)
#Canvas
canvas = Canvas(width=280, height=224, bg=YELLOW, highlightthickness=0)
tomato_img = PhotoImage(file='C:/Pomodoro/tomato.png')
canvas.create_image(140, 112, image=tomato_img)
timer_text = canvas.create_text(140, 130, text='00:00', fill='white', font=(FONT_NAME, 35, 'bold'))
canvas.grid(column=1, row=1)
#Buttons
start = Button(text='Start', highlightthickness=0, command=start_timer)
start.grid(column=0, row=2)
stop = Button(text='Stop', highlightthickness=0, command=stop_timer)
stop.grid(column=1, row=4)
reset = Button(text='Reset', highlightthickness=0, command=reset_timer)
reset.grid(column=2, row=2)
#Checkmarks
check_marks = Label(text='', fg=GREEN, bg=YELLOW)
check_marks.grid(column=1, row=3)
window.mainloop()