Skip to content

Commit b32ea1a

Browse files
authored
Merge pull request #283 from maxcohen31/pomodoro_timer
Adding pomodoro timer to GUI folder
2 parents 117fe9d + 6747701 commit b32ea1a

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

GUI/Pomodoro Timer/Pomodoro_timer.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import tkinter as Tk
2+
from tkinter import Button
3+
from tkinter import Label
4+
from tkinter import StringVar
5+
from tkinter import messagebox
6+
from pygame import mixer
7+
8+
# window geometry
9+
HEIGTH = 700
10+
WIDTH = 500
11+
12+
# palette
13+
BUTTON_GRAPHIC = {
14+
'bd': 4,
15+
'fg': '#F0F8FF',
16+
'bg': 'red',
17+
'font': ('arial', 13),
18+
'width': 2,
19+
'height': 2,
20+
'relief': 'flat',
21+
'activebackground': 'green'
22+
}
23+
24+
WINDOW_COLOR = {'bg': 'black'}
25+
26+
class PomodoroTimer:
27+
28+
tot_seconds = 50 * 60
29+
30+
def __init__(self, window):
31+
mixer.init()
32+
self.window = window
33+
self.stop = False
34+
self.start = False
35+
self.window.title('Hocus pocus keep tha focus!')
36+
self.window.geometry(f"{HEIGTH}x{WIDTH}")
37+
self.window.configure(**WINDOW_COLOR)
38+
self.sound = mixer.Sound('Success.wav')
39+
40+
# method containing the main logic
41+
def start_timer(self):
42+
self.start = True
43+
if self.start and not self.stop:
44+
if self.tot_seconds > 0:
45+
minute, seconds = divmod(self.tot_seconds, 60)
46+
self.min_.set(f"{minute:02d}")
47+
self.sec.set(f"{seconds:02d}")
48+
self.tot_seconds -= 1
49+
self.start_button.config(state=Tk.DISABLED)
50+
self.window.after(1000, self.start_timer)
51+
52+
elif self.stop_timer:
53+
self.start = True
54+
self.stop = False
55+
self.start_button.config(state=Tk.NORMAL)
56+
57+
elif self.reset_timer:
58+
self.start_timer()
59+
60+
if self.tot_seconds == 0:
61+
self.stop = True
62+
self.break_time()
63+
64+
def break_time(self):
65+
self.start = False
66+
self.tot_seconds = 50 * 60
67+
self.sound.play(1)
68+
messagebox.showinfo(title='Pause', message='Time to take a 10 minutes break!')
69+
70+
def stop_timer(self):
71+
if self.start and not self.stop:
72+
self.start = False
73+
self.stop = True
74+
75+
def reset_timer(self):
76+
self.stop = True
77+
self.min_.set('50')
78+
self.sec.set('00')
79+
self.tot_seconds = 50 * 60
80+
81+
def main(self):
82+
83+
self.min_ = StringVar()
84+
self.sec = StringVar()
85+
self.min_.set('50')
86+
self.sec.set('00')
87+
88+
# main buttons - START, RESET, STOP
89+
self.start_button = Button(self.window, text='START', padx=30, pady=20, **BUTTON_GRAPHIC, command=self.start_timer)
90+
self.reset_button = Button(self.window, text='RESET', padx=30, pady=20, **BUTTON_GRAPHIC, command=self.reset_timer)
91+
self.stop_button = Button(self.window, text='STOP', padx=30, pady=20, **BUTTON_GRAPHIC, command=self.stop_timer)
92+
93+
# display
94+
self.set_minute_display = Label(self.window, textvariable=self.min_, font=('bold', 30)).place(x=100, y=120, width=200, height=100)
95+
self.set_seconds_display = Label(self.window, textvariable=self.sec, font=('bold', 30)).place(x=400, y=120, width=200, height=100)
96+
97+
# buttons placement
98+
self.start_button.place(x=300, y=390)
99+
self.reset_button.place(x=200, y=390)
100+
self.stop_button.place(x=400, y=390)
101+
102+
# initialize window
103+
self.window.mainloop()
104+
105+
# Main driver
106+
if __name__ == "__main__":
107+
timer = PomodoroTimer(Tk.Tk())
108+
timer.main()

GUI/Pomodoro Timer/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Pomodoro-Timer
2+
Pomodoro Timer made with Tkinter to help you study
3+
4+
# Usage
5+
Clone the repository then
6+
7+
```cd Python-project-Scripts/GUI/Pomodoro Timer ; python3 Pomodoro_timer.py```
8+
9+
# Screenshot
10+
![image](screenshot.png)

GUI/Pomodoro Timer/Success.wav

579 KB
Binary file not shown.

GUI/Pomodoro Timer/screenshot.png

51.8 KB
Loading

0 commit comments

Comments
 (0)