Summary

Resources

Notes\ Code

image.png

Almost done with our Pomodoro clock, we just need to work on our checkmarks. Currently our checkmark code looks like this:

check_marks = Label(text="✔", fg=GREEN, bg=YELLOW)
check_marks.grid(column=1, row=3)

But we want the text to be empty now as we will add a checkmark each time the user completes a work session. Heres how our label code should look now.

check_marks = Label(fg=GREEN, bg=YELLOW)
check_marks.grid(column=1, row=3)

What we want to do now is as our countdown goes down we want to add a checkmark each time we finish a work timer. Work timers occur every other interval so we can say each time the global variable reps is divided evenly by 2 we will a checkmark. To do this we need to modify our countdown function. We create a placeholder variable called marks, then another variable work sessions to hold our math. To also prevent python from rounding up, we use the math floor function to prevent checkmarks being added during the work break timers. We then just need to modify our checkmarks label with config adding the amount of checkmarks that have been added to the marks placeholder.

def count_down(count):
    global reps
    count_min = math.floor(count / 60)
    count_sec = 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:
        window.after(1000, count_down, count - 1)
    else:
        start_timer()
        marks = ""
        work_sessions = math.floor(reps/2)
        for _ in range(work_sessions):
            marks += "✔"
        check_marks.config(text=marks)

Lastly we need to work on our reset mechanism, which will reset the text for timer, stop the timer, reset the checkmarks and change the title back to “Timer” indicating we are not currently in a work session or a break session.

Let’s start by stopping the timer. The line of code we actually want to stop is the window.after() in the if statement of our countdown.

if count > 0:
    window.after(1000, count_down, count - 1)

We can stop this line with after_cancel() but to do this we need to put our window.after line above into a variable. Lets do that.