-
Notifications
You must be signed in to change notification settings - Fork 1
/
pomodoro.py
74 lines (60 loc) · 3.01 KB
/
pomodoro.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
"""The source code for the pomodoro app, source code borrowed and modified from
https://github.com/achudnova/projects-yt/blob/main/Pomodoro/pomodoro.py"""
import tkinter as tk
from tkinter import messagebox
from ttkbootstrap import ttk, Style
# Set the default time for work and break intervals
WORK_TIME = 25 * 60
SHORT_BREAK_TIME = 5 * 60
LONG_BREAK_TIME = 15 * 60
class PomodoroTimer:
def __init__(self):
self.root = tk.Tk()
self.root.geometry("200x200")
self.root.title("Pomodoro Timer")
self.style = Style(theme="simplex")
self.style.theme_use()
self.timer_label = tk.Label(self.root, text="", font=("TkDefaultFont", 40))
self.timer_label.pack(pady=20)
self.start_button = ttk.Button(self.root, text="Start", command=self.start_timer)
self.start_button.pack(pady=5)
self.stop_button = ttk.Button(self.root, text="Stop", command=self.stop_timer,
state=tk.DISABLED)
self.stop_button.pack(pady=5)
self.work_time, self.break_time = WORK_TIME, SHORT_BREAK_TIME
self.is_work_time, self.pomodoros_completed, self.is_running = True, 0, False
self.root.mainloop()
def start_timer(self):
self.start_button.config(state=tk.DISABLED)
self.stop_button.config(state=tk.NORMAL)
self.is_running = True
self.update_timer()
def stop_timer(self):
self.start_button.config(state=tk.NORMAL)
self.stop_button.config(state=tk.DISABLED)
self.is_running = False
def update_timer(self):
if self.is_running:
if self.is_work_time:
self.work_time -= 1
if self.work_time == 0:
self.is_work_time = False
self.pomodoros_completed += 1
self.break_time = LONG_BREAK_TIME if self.pomodoros_completed % 4 == 0 else SHORT_BREAK_TIME
messagebox.showinfo("Great job!" if self.pomodoros_completed % 4 == 0
else "Good job!", "Take a long break and rest your mind."
if self.pomodoros_completed % 4 == 0
else "Take a short break and strech your legs!")
else:
self.break_time -= 1
if self.break_time == 0:
self.is_work_time, self.work_time = True, WORK_TIME
messagebox.showinfo("Work TIie", "Get back to work!")
minutes, seconds = divmod(self.work_time if self.is_work_time else self.break_time, 60)
self.timer_label.config(text="{:02d}:{:02d}".format(minutes, seconds))
self.root.after(1000, self.update_timer)
if __name__ == '__main__':
WORK_TIME = int(input("How long would you like to study for?: ")) * 60
SHORT_BREAK_TIME = int(input("How long would you like your short break to be?: ")) * 60
LONG_BREAK_TIME = int(input("How long would you like your long break to be?: ")) * 60
PomodoroTimer()