Skip to content
    Pomodoro Timer@carriebrammer
    .gitignore
    main.py
    tomato.png
    Packager files
    poetry.lock
    pyproject.toml
    Config files
    .replit
    from tkinter import *
    import math


    # ---------------------------- CONSTANTS ------------------------------- #
    PINK = "#e2979c"
    RED = "#e7305b"
    GREEN = "#9bdeac"
    YELLOW = "#f7f5dd"
    FONT_NAME = "Courier"
    WORK_MIN = .04
    SHORT_BREAK_MIN = .04
    LONG_BREAK_MIN = .04
    REPS = 0
    CHECKS = ""
    timer = None


    # ---------------------------- TIMER RESET ------------------------------- #
    def reset_timer():
    window.after_cancel(timer)
    canvas.itemconfig(timer_text, text="00:00")
    timer_label.config(text="Timer", fg=GREEN, bg=YELLOW)
    CHECKS = ""
    check_marks.config(text=CHECKS)
    global REPS
    REPS = 0


    # ---------------------------- TIMER MECHANISM ------------------------------- #
    def start_timer():
    global REPS
    work_sec = WORK_MIN * 60
    short_break_sec = SHORT_BREAK_MIN * 60
    long_break_sec = LONG_BREAK_MIN * 60
    REPS += 1
    if REPS % 8 == 0:
    countdown(long_break_sec)
    timer_label.config(text="Break", bg=YELLOW, fg=RED)
    elif REPS % 2 == 0:
    countdown(short_break_sec)
    timer_label.config(text="Break", bg=YELLOW, fg=PINK)
    else:
    countdown(work_sec)
    timer_label.config(text="Work", bg=YELLOW, fg=GREEN)


    # ---------------------------- COUNTDOWN MECHANISM ------------------------------- #
    def countdown(count):
    count_min = math.floor(count / 60)
    if len(str(count_min)) < 2:
    count_min = f"0{count_min}"
    global CHECKS
    global timer

    count_sec = math.floor(count % 60)
    if count_sec < 10:
    count_sec = f"0{count_sec}"

    canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")
    if count > 0:
    timer = window.after(1000, countdown, count - 1)

    else:
    start_timer()
    if REPS == 2 or REPS == 4 or REPS == 6 or REPS == 8:
    CHECKS += "✔"
    check_marks.config(text=CHECKS)


    # ---------------------------- UI SETUP ------------------------------- #
    window = Tk()
    window.title("Pomodoro Timer")
    window.config(padx=50, pady=20, bg=YELLOW)


    canvas = Canvas(width=200, height=224, bg=YELLOW, highlightthickness=0)
    tomato_img = PhotoImage(file="tomato.png")
    canvas.create_image(100, 112, image=tomato_img)

    timer_label = Label(text="TIMER", bg=YELLOW, fg=GREEN, font=(FONT_NAME, 35, 'bold'))
    timer_label.grid(column=1, row=1)

    timer_text = canvas.create_text(100, 130, text="00:00", fill="white", font=(FONT_NAME, 35, 'bold'))
    canvas.grid(column=1, row=2)

    start_button = Button(text="START", bg=GREEN, font=(FONT_NAME, 12, 'normal'), highlightthickness=0, command=start_timer)
    start_button.grid(column=0, row=3)

    reset_button = Button(text="RESET", bg=GREEN, font=(FONT_NAME, 12, 'normal'), highlightthickness=0, command=reset_timer)
    reset_button.grid(column=2, row=3)

    check_marks = Label(text=CHECKS, bg=YELLOW, fg=GREEN, font=(FONT_NAME, 16, 'bold'), pady=30)
    check_marks.grid(column=1, row=4)

    window.mainloop()