-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (86 loc) · 2.94 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
import math
from tkinter import *
import time
# ---------------------------- CONSTANTS ------------------------------- #
PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
WORK_MIN = 0.3
SHORT_BREAK_MIN = 0.1
LONG_BREAK_MIN = 0.2
reps = 0
checkMarks = ""
timer = None
# ---------------------------- TIMER RESET ------------------------------- #
def reset_timer():
global checkMarks
global timer
global reps
reps = 0
checkMarks = ""
window.after_cancel(timer)
canvas.itemconfig(timer_text, text="00:00")
label.config(text="Timer", bg=PINK)
window.config(bg=PINK)
check_mark_row.config(bg=PINK ,fg=GREEN, text=checkMarks)
canvas.config(bg=PINK)
# ---------------------------- TIMER MECHANISM ------------------------------- #
def start_timer():
global reps
global checkMarks
reps += 1
global work_count
if reps % 8 == 0:
label.config(text="Long Break", bg=RED)
window.config(bg=RED)
check_mark_row.config(bg=RED)
canvas.config(bg=RED)
count_down(LONG_BREAK_MIN*60)
elif reps % 2 == 0:
label.config(text="Short Break",bg=YELLOW)
window.config(bg=YELLOW)
check_mark_row.config(bg=YELLOW)
canvas.config(bg=YELLOW)
count_down(SHORT_BREAK_MIN*60)
else:
label.config(text="Work Time", bg=GREEN)
window.config(bg=GREEN)
check_mark_row.config(bg=GREEN, fg=RED)
canvas.config(bg=GREEN)
count_down(WORK_MIN*60)
checkMarks = ''.join("✔" for mark in checkMarks)
checkMarks += "🔘"
check_mark_row.config(text=checkMarks)
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def count_down(count):
count_min = math.floor(count/60)
count_seconds = count % 60
if count_seconds < 10:
count_seconds = f"0{count_seconds}"
canvas.itemconfig(timer_text, text=f"{count_min}:{count_seconds}")
if count > 0:
global timer
timer = window.after(1000, count_down, count-1)
else:
start_timer()
# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title("Pomodoro")
window.config(padx=100, pady=50, bg=PINK)
label = Label(text="Timer",font=(FONT_NAME, 40, "bold"), bg= PINK, fg=GREEN)
label.grid(row=0, column=1)
canvas = Canvas(width=200, height=224,bg=PINK, highlightthickness=0)
bg_image = PhotoImage(file="tomato.png")
canvas.create_image(100, 112, image=bg_image)
timer_text = canvas.create_text(100, 130, text="00:00", fill="white", font=(FONT_NAME, 35, "bold"))
canvas.grid(row=1, column=1)
start_button = Button(text="Start", command=start_timer)
start_button.grid(row=2, column=0)
reset_button = Button(text="Reset", command=reset_timer)
reset_button.grid(row=2, column=2)
check_mark_row = Label(text=checkMarks, fg=GREEN, bg=PINK)
check_mark_row.config(pady=10, padx=20)
check_mark_row.grid(row=3, column=1)
window.mainloop()