I am trying to make pomodoro software. However, my counter doesn't work at all. I couldn't understand the reason. I hope you can help me to solve this issue. I basically try to count down from 25 minutes with seconds if my mode is working mode. If my work is break mode, I want to count down from 5 minutes. Many thanks in advance.
# ---------------------------- CONSTANTS ------------------------------- #
PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
WORK_MIN = 25
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 20
# ---------------------------- TIMER RESET ------------------------------- #
def reset_time(mode):
if mode == "working":
minutes = 25
seconds = 0
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
elif mode == "break":
minutes = 5
seconds = 0
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
# ---------------------------- TIMER MECHANISM ------------------------------- #
def start_timer(mode,start):
if mode == "working":
minutes = 24
seconds = 59
if start == 0:
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
start += 1
elif mode == "break":
minutes = 4
seconds = 59
if start == 0:
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
start += 1
count(mode,minutes,seconds)
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
def count(mode, minutes, seconds):
if mode == "working":
while seconds <= 60:
if seconds == 0:
if minutes == 0 and seconds == 0:
mode = "break"
start = 0
break
seconds = 60
minutes -= 1
seconds -= 1
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
elif mode == "break":
while seconds <= 60:
if seconds == 0:
if minutes == 0 and seconds == 0:
mode = "working"
start = 0
break
seconds = 60
minutes -= 1
seconds -= 1
canvas.itemconfig(time_c, text=f"{minutes}:{seconds}")
# ---------------------------- UI SETUP ------------------------------- #
from tkinter import *
mode = "working"
start = 0
minutes=25
seconds=0
window = Tk()
window.title("Pomodoro Powered By MFE")
window.minsize(width=300, height=300)
window.configure(padx=100, pady=50, bg=YELLOW)
label_timer = Label(text="Timer", fg=GREEN, bg=YELLOW, font=(FONT_NAME, 20, "bold"))
label_timer.grid(column=2, row=1)
canvas = Canvas(window, width=210, height=223, bg=YELLOW, highlightthickness=0)
canvas.grid(column=2, row=2)
img = PhotoImage(file="tomato.png")
img_sip = canvas.create_image(7, 0, anchor=NW, image=img)
time_c = canvas.create_text(100, 112, text=f"{minutes},{seconds}", fill="white", font=(FONT_NAME, 30, "bold"))
button_start = Button(text="Start", bg="white", command=start_timer(mode=str(mode),start=start), highlightthickness=0)
button_start.grid(ipadx=2, ipady=2, column=1, row=3)
button_reset = Button(text="Reset", bg="white", command=reset_time(mode=str(mode)), highlightthickness=0)
button_reset.grid(ipadx=2, ipady=2, column=3, row=3)
label_tick = Label(text="✔", bg=YELLOW, fg=GREEN, font=(FONT_NAME, 15, "bold"))
label_tick.grid(column=2, row=3)
window.mainloop()