finished the logic and added a nice UI :>

This commit is contained in:
2026-06-10 20:11:54 +03:00
parent 7627d01425
commit c17348dcd4

46
main.py
View File

@@ -17,12 +17,13 @@ distractions = 0
width = 120 width = 120
height = 140 height = 140
app = tk.Tk() app = tk.Tk(className="focustimer")
app.title("Focus-Timer") app.title("Focus-Timer")
app.configure(background="#17153B") app.configure(background="#17153B")
app.geometry(f"{width}x{height}") app.geometry(f"{width}x{height}")
app.minsize(width, height) app.minsize(width, height)
app.maxsize(width, height) app.maxsize(width, height)
app.update()
app.resizable(False, False) app.resizable(False, False)
@@ -30,9 +31,9 @@ def tick():
global seconds_left, current_state global seconds_left, current_state
match current_state: match current_state:
case STATE_IDLE: case "IDLE":
return return
case STATE_OVERTIME: case "OVERTIME":
seconds_left += 1 seconds_left += 1
case _: case _:
seconds_left -= 1 seconds_left -= 1
@@ -55,7 +56,7 @@ def handle_transition():
match current_state: match current_state:
case "FOCUS": case "FOCUS":
current_state = STATE_WORK current_state = STATE_WORK
seconds_left = 4200 # 70 min seconds_left = 4200
distractions = 0 distractions = 0
case "WORK": case "WORK":
@@ -66,6 +67,7 @@ def handle_transition():
current_state = STATE_IDLE current_state = STATE_IDLE
seconds_left = 0 seconds_left = 0
update_timer_label()
update_ui() update_ui()
def start_button_f(): def start_button_f():
@@ -99,6 +101,7 @@ def break_button_f():
seconds_left = 1500 seconds_left = 1500
update_timer_label() update_timer_label()
create_post()
update_ui() update_ui()
def complete_task_button_f(): def complete_task_button_f():
@@ -138,46 +141,47 @@ def update_ui():
match current_state: match current_state:
case "IDLE": case "IDLE":
text_label.config(text="Wanna start?") text_label.config(text="Wanna start?", fg="#C8ACD6")
timer_label.config(text="00:20:00") timer_label.config(text="00:20:00", fg="#C8ACD6")
start_button.config(fg="#c8acd6", activebackground="#c8acd6")
start_button.pack(side="bottom",pady="15") start_button.pack(side="bottom",pady="15")
case "FOCUS": case "FOCUS":
text_label.config(text="Time to focus!") text_label.config(text="Time to focus!", fg="red")
timer_label.config() timer_label.config(fg="red")
distracted_button.pack(side="bottom", pady="15") distracted_button.pack(side="bottom", pady="15")
case "WORK": case "WORK":
text_label.config(text="Work.") text_label.config(text="Work.", fg="aqua")
timer_label.config() timer_label.config(fg="aqua")
complete_task_button.pack(side="bottom", pady="15") complete_task_button.pack(side="bottom", pady="15")
case "OVERTIME": case "OVERTIME":
text_label.config(text="Maybe a break?") text_label.config(text="Maybe a break?", fg="orange")
timer_label.config() timer_label.config(fg="orange")
break_button.pack(side="bottom", pady="15") break_button.pack(side="bottom", pady="15")
case "BREAK": case "BREAK":
text_label.config(text="Relax..") text_label.config(text="Relax..", fg="yellow")
timer_label.config() timer_label.config(fg="yellow")
start_button.config(fg="yellow", activebackground="yellow")
start_button.pack(side="bottom", pady="15") start_button.pack(side="bottom", pady="15")
text_label = tk.Label(app, text="", font=("Helvetica", 14)) text_label = tk.Label(app, font=("Helvetica", 14, "bold"), bg="#17153b")
text_label.pack(side="top", pady="15") text_label.pack(side="top", pady="15")
timer_label = tk.Label(app, text="hh:mm:ss",fg="#C8ACD6",background="#17153B",font=("Helvetica", 25) , anchor="center") timer_label = tk.Label(app, text="hh:mm:ss",fg="#C8ACD6",background="#17153B",font=("Helvetica", 25) , anchor="center")
timer_label.pack(expand=True,fill="y") timer_label.pack(expand=True,fill="y")
start_button = tk.Button(app, text="Start.", command=start_button_f) start_button = tk.Button(app, text="Start.", command=start_button_f, activeforeground="black", background="#17153b", relief="flat", bd="0")
distracted_button = tk.Button(app, text="I got distracted.", command=distracted_button_f) distracted_button = tk.Button(app, text="I got distracted.", command=distracted_button_f, fg="red", bg="#17153b", relief="flat", bd="0", activebackground="red", activeforeground="black")
complete_task_button = tk.Button(app, text="Complete the task.", command=complete_task_button_f)
break_button = tk.Button(app, text="Go break :3", command=break_button_f)
complete_task_button = tk.Button(app, text="Complete the task.", command=complete_task_button_f, fg="aqua", bg="#17153b", relief="flat", bd="0", activebackground="aqua", activeforeground="black")
break_button = tk.Button(app, text="Go break :3", command=break_button_f, fg="orange", bg="#17153b", relief="flat", bd="0", activebackground="orange", activeforeground="black")
update_ui() update_ui()
app.mainloop() app.mainloop()