from tkinter import *
import tkinter.ttk as ttk
import datetime as dt
class Window(Frame):
def __init__(self, root):
Frame.__init__(self, root)
self.is_running = True
self.all_time = 0
self.button_5_min = Button(
self, text='5 мин', command=lambda: self.set_timer(5)
)
self.button_10_min = Button(
self, text='10 мин', command=lambda: self.set_timer(10*60)
)
self.button_20_min = Button(
self, text='20 мин', command=lambda: self.set_timer(20*60)
)
self.button_30_min = Button(
self, text='30 мин', command=lambda: self.set_timer(30*60)
)
self.button_40_min = Button(
self, text='40 мин', command=lambda: self.set_timer(40*60)
)
self.button_50_min = Button(
self, text='50 мин', command=lambda: self.set_timer(50*60)
)
self.button_1_hour = Button(
self, text='1 час', command=lambda: self.set_timer(60*60)
)
self.start_stop_button = Button(
self, text='Старт', command=lambda: self.start_stop()
)
self.label = Label(self, text='Установите таймер', font=1)
self.pb = ttk.Progressbar(self, mode='determinate', length=551)
self.pb.pack()
self.start_stop_button.pack(side=BOTTOM)
self.label.pack(side=BOTTOM)
self.button_5_min.pack(side=LEFT)
self.button_10_min.pack(side=LEFT)
self.button_20_min.pack(side=LEFT)
self.button_30_min.pack(side=LEFT)
self.button_40_min.pack(side=LEFT)
self.button_50_min.pack(side=LEFT)
self.button_1_hour.pack(side=LEFT)
def set_timer(self, interval):
self.all_time += interval
self.label.configure(
text=dt.timedelta(seconds=self.all_time), font=1
)
self.pb['maximum'] = self.all_time
def reset(self):
self.pb['value'] = 0
self.all_time = 0
self.is_running = False
self.start_stop_button.configure(
text='Старт', command=lambda: self.start_stop()
)
self.label.configure(text='Установите таймер', font=1)
def start_stop(self):
if self.all_time == 0:
if self.is_running is False:
self.is_running = True
return
print('\a')
self.label.configure(
text='Отдохните от компьютера и возвращайтесь к работе', font=1
)
self.start_stop_button.configure(
text='Старт', command=lambda: self.start_stop()
)
self.pb['value'] = 0
return
self.start_stop_button.configure(
text='Сброс', command=lambda: self.reset()
)
self.pb['value'] += 1
self.all_time -= 1
self.label.configure(
text=dt.timedelta(seconds=self.all_time), font=1
)
self.after(1000, self.start_stop)
if __name__ == "__main__":
root = Tk()
window = Window(root)
window.pack()
root.title('TiPymer')
root.resizable(width=False, height=False)
root.mainloop()