Skip to content

Commit 9d3707b

Browse files
committed
Added pomodoro timer
1 parent d081e05 commit 9d3707b

File tree

2 files changed

+203
-0
lines changed

2 files changed

+203
-0
lines changed

pomodoro_timer/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# GUI Pomodoro Timer
2+
3+
- A pomodoro timer with customisable time options.
4+
- The user can select the pre-defined timer options.
5+
- Or the user can enter custome work/break periods
6+
7+
## Usage
8+
9+
- Copy the contents of the folder into your desired location
10+
- Execute the script `python pomodoro_timer.py`
11+
- No packages to install.
12+
13+
### Instructions
14+
This application is intuitive and easy to use :-
15+
- Select the predefined pomodoro options
16+
- Or enter your own work/break timings
17+
- Work until the work timer ends
18+
- Take a break until break timer ends
19+
- This will go on for 4 cycles in total
20+
21+
22+
## Authors
23+
24+
- [@SwarajBaral](https://www.github.com/SwarajBaral)
25+

pomodoro_timer/pomodoro_timer.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import ctypes
2+
import os
3+
import time
4+
from tkinter import Button, Entry, Frame, Label, Tk
5+
from tkinter.constants import BOTTOM, FLAT, LEFT
6+
from tkinter.font import BOLD
7+
import threading
8+
import winsound
9+
10+
ctypes.windll.shcore.SetProcessDpiAwareness(True)
11+
12+
root = Tk()
13+
root.config(bg="Salmon")
14+
root.geometry('600x500')
15+
root.title("Pomodoro Timer")
16+
root.resizable(0, 0)
17+
18+
POMO_OPTIONS = {
19+
0: (25, 5),
20+
1: (20, 10),
21+
}
22+
23+
24+
def user_start():
25+
custom_work = int(user_input_work.get())
26+
custom_break = int(user_input_break.get())
27+
start_timer_params = (custom_work, custom_break)
28+
return threading.Thread(
29+
target=start_timer, args=[start_timer_params]).start()
30+
31+
32+
def today():
33+
day = time.strftime("%a")
34+
hour = time.strftime("%I")
35+
minutes = time.strftime("%M")
36+
ampm = time.strftime("%p")
37+
date_label.config(text=f"{day} {hour}:{minutes} {ampm}")
38+
date_label.after(1000, today)
39+
40+
41+
def reset():
42+
title_label.config(text="Focus...")
43+
timer_label.config(text="Timer Here")
44+
root.geometry("600x500")
45+
button_frame.pack(pady=10)
46+
cycle_label.pack_forget()
47+
input_frame.pack(pady=20)
48+
instruction_label.pack()
49+
return
50+
51+
52+
def start_timer(options, cycle_limit=5):
53+
root.geometry("600x250")
54+
cycles = 1
55+
_work = int(options[0] * 60)
56+
_break = int(options[1] * 60)
57+
button_frame.pack_forget()
58+
input_frame.pack_forget()
59+
instruction_label.pack_forget()
60+
while cycles < cycle_limit:
61+
cycle_label.config(text=f"Cycle no - {cycles}")
62+
cycle_label.pack()
63+
temp_work = _work
64+
temp_break = _break
65+
while temp_work:
66+
title_label.config(text="You should be working now.")
67+
minutes, seconds = divmod(temp_work, 60)
68+
timer_label.config(text=f"{minutes}:{seconds}")
69+
root.update_idletasks()
70+
time.sleep(1)
71+
temp_work -= 1
72+
winsound.Beep(323, 250)
73+
winsound.Beep(583, 250)
74+
while temp_break:
75+
title_label.config(text="You should be taking a break now.")
76+
minutes, seconds = divmod(temp_break, 60)
77+
timer_label.config(text=f"{minutes}:{seconds}")
78+
root.update_idletasks()
79+
time.sleep(1)
80+
temp_break -= 1
81+
winsound.Beep(523, 250)
82+
winsound.Beep(783, 250)
83+
cycles += 1
84+
85+
reset()
86+
return
87+
88+
89+
# Title
90+
title_label = Label(root, text="Focus...",
91+
font=("MV Boli", 20, BOLD),
92+
bg="Salmon")
93+
title_label.pack()
94+
95+
# Cycle Number
96+
cycle_label = Label(root, font=("Consolas", 20, BOLD),
97+
bg="Salmon")
98+
99+
# Pomodoro Timer
100+
timer_label = Label(root, text="Timer here",
101+
bg="black", fg="green", font=("Consolas", 32),
102+
width=10)
103+
timer_label.pack(pady=20)
104+
105+
# Pomodoro Cycle Button Options
106+
button_frame = Frame(root, bg="salmon")
107+
button_frame.pack(pady=10)
108+
109+
pom_one = Button(button_frame, text="25/5 Cycle", font="Helvetica 12",
110+
height=1, width=12,
111+
command=lambda: threading.Thread(
112+
target=start_timer, args=[POMO_OPTIONS[0]]
113+
).start()
114+
)
115+
pom_one.grid(row=0, column=0, padx=5)
116+
pom_two = Button(button_frame, text="20/10 Cycle", font="Helvetica 12",
117+
height=1, width=12,
118+
command=lambda: threading.Thread(
119+
target=start_timer, args=[POMO_OPTIONS[1]]
120+
).start()
121+
)
122+
pom_two.grid(row=0, column=1)
123+
124+
# User input time options
125+
input_frame = Frame(root, bg="salmon")
126+
input_frame.pack(pady=20)
127+
128+
custom_label = Label(
129+
input_frame, text="Enter Custom work/break", bg="salmon", font="Serif 10")
130+
custom_label.grid(row=0, column=0, columnspan=2)
131+
132+
input_label_work = Label(input_frame, text="Work (in mins)",
133+
bg="salmon", font="Serif 10")
134+
input_label_break = Label(input_frame, text="Break (in mins)",
135+
bg="salmon", font="Serif 10")
136+
137+
input_label_work.grid(row=2, column=0)
138+
input_label_break.grid(row=2, column=1)
139+
140+
user_input_work = Entry(input_frame, font=(
141+
"Sans Serif", 12), relief=FLAT, width=10)
142+
user_input_break = Entry(input_frame, font=(
143+
"Sans Serif", 12), relief=FLAT, width=10)
144+
145+
user_input_work.grid(row=1, column=0)
146+
user_input_break.grid(row=1, column=1, padx=10)
147+
148+
user_input_start = Button(input_frame, text="Start",
149+
font=("Sans Serif", 8),
150+
relief=FLAT, command=user_start)
151+
user_input_start.grid(row=1, column=2)
152+
153+
# Date time label
154+
date_label = Label(root, text="Datetime:",
155+
font=("Consolas", 14), bg="salmon")
156+
date_label.pack(side=BOTTOM)
157+
158+
159+
# Instruction Label
160+
instruction_label = Label(
161+
root,
162+
text='''
163+
• Select the predefined pomodoro options
164+
• Or enter your own work/break timings
165+
• Work until the work timer ends
166+
• Take a break until break timer ends
167+
• This will go on for 4 cycles in total
168+
''',
169+
font="Serif 12 bold",
170+
justify=LEFT,
171+
bg="salmon"
172+
)
173+
instruction_label.pack()
174+
175+
if __name__ == "__main__":
176+
os.system('python -m flake8 .')
177+
threading.Thread(target=today).start()
178+
root.mainloop()

0 commit comments

Comments
 (0)