-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.py
250 lines (203 loc) · 7.03 KB
/
timer.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
from tkinter import *
import pygame
from tkinter import font
import time
from tkinter import messagebox
pygame.init()
#window
root=Tk()
root.geometry('600x300')
root.title('Pomodoro Timer')
root.configure(bg='red')
root.iconbitmap('./images/pomodoroIcon.ico')
canvas = Canvas()
root.resizable(False, False)
#consts
red='#d04e2f'
peach='#FFE4B6'
#beep=pygame. mixer.music.load('pomodoro_beep.mp3')
bg_img=PhotoImage(file='./images/timer.png')
pink='#FFC5C5'
#tracker or whatever it's called
cycle =0
current_time=None
short_breaktime=False
long_breaktime=False
breaktime=False
#backgground
bg=Label(root, image=bg_img)
bg.pack()
#time tracker
hrs = StringVar(root, value='00')
hrs.set("00")
Entry(root, textvariable=hrs, fg='black', width=2, font='arial 40', borderwidth=0, ). place(x='100',y='80')
Label(root, text='HOURS', bg='white').place(x='180',y='120')
mins=StringVar(root, value='00')
Entry(root, textvariable=mins, width='2',fg='black', font='arial 40',borderwidth=0).place(x='250',y='80')
Label(root,text='MINS', bg='white').place(x='330',y='120')
mins.set("00")
sec=StringVar(root, value='00')
Entry(root, textvariable=sec, width=2, fg='black', font='arial 40',borderwidth=0, bg='white'). place(x='400',y='80')
Label(root,text='SEC', bg='white').place(x='470',y='120')
sec.set("00")
#starts time
def start_timer():
global time_run
time_run=True
timer()
def pause_timer():
global time_run
time_run=False
print('timer has paused')
global current_time
root.after_cancel(current_time) #cancels the operation above
global pause_popup
global pausebg
pausebg=PhotoImage(file='./pausepopup.png')
pause_popup = Toplevel()
pause_popup.title(f'Don\'t give up!')
pause_popup.geometry('300x200')
pause_popup.resizable(False,False)
pause_popup.iconbitmap('./images/sad.ico')
pause_popupbg=Label(pause_popup,image=pausebg)
pause_popupbg.pack()
pausemsg=Label(pause_popup, text='DON’T STOP UNTIL YOU’RE PROUD.', font=('arial 10 bold'), bg='#FAF9F7')
pausemsg.place(x='35', y='70')
def stop_timer():
global time_run
time_run=False
hrs.set('00')
mins.set('00')
sec.set('00')
def break_mode():
print('hellow world')
global bg_timer
bg_timer=PhotoImage(file='./images/BREAK.png')
bg.config(image=bg_timer)
break_noti.destroy()
def study_mode():
bg.config(image=bg_img)
hrs.set('00')
mins.set('00')
sec.set('00')
def studynotigone():
study_noti.destroy()
def start_break_timer():
global initial_break_time, time_run
initial_break_time = int(hrs.get()) * 3600 + int(mins.get()) * 60 + int(sec.get())
time_run = True
timer() # Start the break timer countdown
def timer():
global time_run, current_time, breaktime,short_breaktime, long_breaktime, cycle, study_mode
total_time = int(hrs.get()) * 3600 + int(mins.get()) * 60 + int(sec.get())
cycletext=Label(root, text='ROUND '+ str(cycle), font='comfortaa 12 bold', background='#FF4545')
cycletext.place(x='80', y='33')
if total_time > 0:
total_time -= 1
hrs.set(str(total_time // 3600).zfill(1))
mins.set(str((total_time % 3600) // 60).zfill(1))
sec.set(str(total_time % 60).zfill(1))
current_time= root.after(1000, timer) #starts countdown
else: #timer 00
if not breaktime:
global break_noti, break_notiimg
breaktime=True
cycle+=1
is_breaktime()
break_presets()
break_notiimg=PhotoImage(file='./images/BREAK_NOTI.png')
break_noti = Toplevel()
break_noti.title(f'Break Time!')
break_noti.geometry('500x300')
break_noti.resizable(False,False)
break_noti.iconbitmap('./images/break_icon.ico')
break_notibg=Label(break_noti,image=break_notiimg)
break_notibg.pack()
break_mode()
else:
global study_noti, studynotiimg
breaktime=False
study_mode()
studynotiimg=PhotoImage(file='./images/STUDY_NOTI.png')
study_noti = Toplevel()
study_noti.title(f'Study Time!')
study_noti.geometry('500x300')
study_noti.resizable(False,False)
study_noti.iconbitmap(r'./images/break_icon.ico')
study_notibg=Label(study_noti,image=studynotiimg)
study_notibg.pack()
studynotigone()
def is_breaktime():
global short_breaktime, long_breaktime
if cycle%4==0:
short_breaktime=False
long_breaktime=True
else:
long_breaktime=False
short_breaktime = True
def break_presets():
work_duration= int(hrs.get())*60 +int(mins.get())
if work_duration <=25:
if short_breaktime:
hrs.set("00")
mins.set("00")
sec.set("03")
elif long_breaktime:
hrs.set("00")
mins.set("15")
sec.set("00")
elif work_duration <=40:
if short_breaktime:
hrs.set("00")
mins.set("10")
sec.set("00")
elif long_breaktime:
hrs.set("00")
mins.set("20")
sec.set("00")
else:
if short_breaktime:
hrs.set("00")
mins.set("15")
sec.set("00")
elif long_breaktime:
hrs.set("00")
mins.set("25")
sec.set("00")
#time presets
def worka():
hrs.set("00")
mins.set("00")
sec.set("5")
if is_breaktime==True:
break_presets()
def workb():
hrs.set('00')
mins.set('40')
sec.set('00')
if is_breaktime==True:
break_presets()
def workc():
hrs.set('01')
mins.set('00')
sec.set('00')
if is_breaktime==True:
break_presets()
#play, pause and stop buttons
starticon=PhotoImage(file='./images/start.png')
startbutton=Button(root, text='start', image=starticon,bg='white', borderwidth=0,command=start_timer). place(x='260',y=' 230')
pauseicon=PhotoImage(file='./images/pause.png')
pausebutton=Button(root, text='pause', image=pauseicon, bg='white', borderwidth=0, command=pause_timer).place(x='200',y='250')
stopicon=PhotoImage(file='./images/stop.png')
stopbutton=Button(root,text='stop', image=stopicon, bg='white', borderwidth=0, command=stop_timer).place(x='350',y='250')
moyen=PhotoImage(file='./images/MOYEN.png')
moolan=PhotoImage(file='./images/MOOLAN.png')
maria=PhotoImage(file='./images/MARIA.png')
workabutton=Button(root, image=moyen, bg=pink, font='comfortaa 18 bold', borderwidth=0, command=worka)
workabutton.place(x='175',y=' 160')
workbbutton=Button(root, image=moolan, bg=pink, font='comfortaa 18 bold', borderwidth=0, command=workb)
workbbutton.place(x='270',y=' 160')
workcbutton=Button(root, image=maria, bg=pink, font='comfortaa 18 bold', borderwidth=0, command=workc)
workcbutton.place(x='365',y=' 160')
root.mainloop()
root.update()