-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay28.py
More file actions
115 lines (97 loc) · 3.41 KB
/
Day28.py
File metadata and controls
115 lines (97 loc) · 3.41 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
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
115
import math
from tkinter import *
FOREGROUND_COLOUR = "#40A2E3"
BACKGROUND_COLOUR = "#FFE4C9"
WHITE = "white"
PL_FONT = "Palatino Linotype"
BOLD = "bold"
ITALIC = "italic"
ZERO = 0
ONE = 1
TWO = 2
SIXTY = 60
SHORT_BREAK_TIME_MINUTES = 5
LONG_BREAK_TIME_MINUTES = 20
WORK_TIME_MINUTES = 25
HUNDRED = 100
count_timer = 5
WORK_ITERATIONS = ZERO
COUNTER = ZERO
TIMER = ''
print("Day 28 - 100 Days of Code.")
print("Welcome to Pomodoro App.")
def start_pomodoro_timer():
"""
Method to start the pomodoro app.
"""
global WORK_ITERATIONS
WORK_ITERATIONS += ONE
if WORK_ITERATIONS % 8 == ZERO:
title_label.config(text="Break! :)", fg="#430A5D")
add_new_checkmark()
count_down(LONG_BREAK_TIME_MINUTES * SIXTY)
elif WORK_ITERATIONS % TWO == ZERO:
title_label.config(text="Break! :)", fg="#FE7A36")
add_new_checkmark()
count_down(SHORT_BREAK_TIME_MINUTES * SIXTY)
else:
title_label.config(text="Work.", fg="#D63484")
count_down(WORK_TIME_MINUTES * SIXTY)
title_label.grid(column=TWO, row=ZERO)
def reset_pomodoro_timer():
"""
Method to reset the pomodoro app.
"""
global TIMER
try:
window.after_cancel(TIMER)
except ValueError:
pass
global WORK_ITERATIONS
WORK_ITERATIONS = ZERO
checkmark_label["text"] = ""
checkmark_label.grid(column=TWO, row=TWO)
canvas.itemconfig(timer_text, text="00:00")
canvas.grid(column=TWO, row=ONE)
title_label["text"] = "Timer"
title_label.grid(column=TWO, row=ZERO)
def add_new_checkmark():
"""
Method to add a new checkmark after one iteration.
"""
checkmark_label["text"] = "✓" * math.floor(WORK_ITERATIONS / TWO)
checkmark_label.grid(column=TWO, row=TWO)
canvas.itemconfig(timer_text, text="00:00")
canvas.grid(column=TWO, row=ONE)
def count_down(count_value):
"""
Method that starts the countdown for one iteration.
"""
global count_timer
if count_value >= ZERO:
count_value_minute = math.floor(count_value / 60)
count_value_second = count_value % 60
if count_value_second in range(ZERO, 10):
count_value_second = str(ZERO) + str(count_value_second)
count_timer -= ONE
canvas.itemconfig(timer_text, text=f"{count_value_minute}:{count_value_second}")
global TIMER
TIMER = window.after(10, count_down, count_value - ONE)
else:
start_pomodoro_timer()
window = Tk()
window.title("Pomodoro App.")
window.config(padx=HUNDRED, pady=HUNDRED, bg=BACKGROUND_COLOUR)
canvas = Canvas(width=210, height=233, bg=BACKGROUND_COLOUR, highlightthickness=ZERO)
tomato_image = PhotoImage(file="Tomato.png")
canvas.create_image(HUNDRED, HUNDRED, image=tomato_image)
timer_text = canvas.create_text(HUNDRED, 120, text="00:00", font=(PL_FONT, 25, ITALIC), fill=WHITE)
canvas.grid(column=TWO, row=ONE)
title_label = Label(text="Timer", font=("Courier", 30, BOLD), bg=BACKGROUND_COLOUR, fg=FOREGROUND_COLOUR)
title_label.grid(column=TWO, row=ZERO)
start_button = Button(text="Start", font=(PL_FONT, 10, ITALIC), bg=WHITE, command=start_pomodoro_timer)
start_button.grid(column=ONE, row=TWO)
reset_button = Button(text="Reset", font=(PL_FONT, 10, ITALIC), bg=WHITE, command=reset_pomodoro_timer)
reset_button.grid(column=3, row=TWO)
checkmark_label = Label(text="✓", font=(PL_FONT, 20, "normal"), bg=BACKGROUND_COLOUR, fg=FOREGROUND_COLOUR)
window.mainloop()