forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
144 lines (120 loc) · 5.49 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/python3
import time
import threading
import tkinter as tk
from tkinter import ttk, PhotoImage
import os
class PomodoroTimer:
def __init__(self):
self.root = tk.Tk()
self.root.geometry("600x300")
self.root.title("Pomodoro Timer")
# Set the path to your image
icon_path = r"C:\Users\hp\Desktop\pomodoro_clock_gui-main\img.jpg"
try:
icon_image = PhotoImage(file=icon_path)
self.root.iconphoto(False, icon_image)
except Exception as e:
print(f"Error loading icon: {e}") # Print an error if the icon cannot be loaded
self.s = ttk.Style()
self.s.configure("TNotebook.Tab", font=("Ubuntu", 16))
self.s.configure("TButton", font=("Ubuntu", 16))
self.tabs = ttk.Notebook(self.root)
self.tabs.pack(fill="both", pady=10, expand=True)
self.tab1 = ttk.Frame(self.tabs, width=600, height=100)
self.tab2 = ttk.Frame(self.tabs, width=600, height=100)
self.tab3 = ttk.Frame(self.tabs, width=600, height=100)
self.pomodoro_timer_label = ttk.Label(self.tab1, text="25:00", font=("Ubuntu", 48))
self.pomodoro_timer_label.pack(pady=20)
self.short_break_timer_label = ttk.Label(self.tab2, text="05:00", font=("Ubuntu", 48))
self.short_break_timer_label.pack(pady=20)
self.long_break_timer_label = ttk.Label(self.tab3, text="15:00", font=("Ubuntu", 48))
self.long_break_timer_label.pack(pady=20)
self.tabs.add(self.tab1, text="Pomodoro")
self.tabs.add(self.tab2, text="Short Break")
self.tabs.add(self.tab3, text="Long Break")
self.grid_layout = ttk.Frame(self.root)
self.grid_layout.pack(pady=10)
self.start_button = ttk.Button(self.grid_layout, text="Start", command=self.start_timer_thread)
self.start_button.grid(row=0, column=0)
self.skip_button = ttk.Button(self.grid_layout, text="Skip", command=self.skip_clock)
self.skip_button.grid(row=0, column=1)
self.reset_button = ttk.Button(self.grid_layout, text="Reset", command=self.reset_clock)
self.reset_button.grid(row=0, column=2)
self.pomodoro_counter_label = ttk.Label(self.grid_layout, text="Pomodoros: 0", font=("Ubuntu", 16))
self.pomodoro_counter_label.grid(row=1, column=0, columnspan=3, pady=10)
self.pomodoros = 0
self.skipped = False
self.stopped = False
self.running = False
self.root.mainloop()
def start_timer_thread(self):
if not self.running:
t = threading.Thread(target=self.start_timer)
t.start()
self.running = True
def start_timer(self):
self.stopped = False
self.skipped = False
timer_id = self.tabs.index(self.tabs.select()) + 1
if timer_id == 1:
full_seconds = 60 * 25
while full_seconds > 0 and not self.stopped:
minutes, seconds = divmod(full_seconds, 60)
self.pomodoro_timer_label.config(text=f"{minutes:02d}:{seconds:02d}")
self.root.update()
time.sleep(1)
full_seconds -= 1
if not self.stopped or self.skipped:
self.pomodoros += 1
self.pomodoro_counter_label.config(text=f"Pomodoros: {self.pomodoros}")
if self.pomodoros % 4 == 0:
self.tabs.select(2)
self.start_timer()
else:
self.tabs.select(1)
self.start_timer()
elif timer_id == 2:
full_seconds = 60 * 5
while full_seconds > 0 and not self.stopped:
minutes, seconds = divmod(full_seconds, 60)
self.short_break_timer_label.config(text=f"{minutes:02d}:{seconds:02d}")
self.root.update()
time.sleep(1)
full_seconds -= 1
if not self.stopped or self.skipped:
self.tabs.select(0)
self.start_timer()
elif timer_id == 3:
full_seconds = 60 * 15
while full_seconds > 0 and not self.stopped:
minutes, seconds = divmod(full_seconds, 60)
self.long_break_timer_label.config(text=f"{minutes:02d}:{seconds:02d}")
self.root.update()
time.sleep(1)
full_seconds -= 1
if not self.stopped or self.skipped:
self.tabs.select(0)
self.start_timer()
else:
print("Invalid entry")
def reset_clock(self):
self.stopped = True
self.skipped = False
self.pomodoros = 0
self.pomodoro_timer_label.config(text="25:00")
self.short_break_timer_label.config(text="05:00")
self.long_break_timer_label.config(text="15:00")
self.pomodoro_counter_label.config(text="Pomodoros: 0")
self.running = False
def skip_clock(self):
current_tab = self.tabs.index(self.tabs.select())
if current_tab == 0:
self.pomodoro_timer_label.config(text="25:00")
elif current_tab == 1:
self.short_break_timer_label.config(text="05:00")
elif current_tab == 2:
self.long_break_timer_label.config(text="15:00")
self.stopped = True
self.skipped = True
PomodoroTimer()