The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a simple Pomodoro timer with Python

Here’s a simple Pomodoro Timer using Python’s tkinter GUI library. This version follows the classic Pomodoro technique: 25 minutes of focused work followed by a 5-minute break, and a longer break every 4 sessions.

python
import tkinter as tk import math # ---------------------------- CONSTANTS ------------------------------- # WORK_MIN = 25 SHORT_BREAK_MIN = 5 LONG_BREAK_MIN = 15 reps = 0 timer = None # ---------------------------- TIMER RESET ------------------------------- # def reset_timer(): window.after_cancel(timer) canvas.itemconfig(timer_text, text="00:00") title_label.config(text="Timer", fg="#375E97") check_marks.config(text="") global reps reps = 0 # ---------------------------- TIMER MECHANISM ------------------------------- # def start_timer(): global reps reps += 1 if reps % 8 == 0: count_down(LONG_BREAK_MIN * 60) title_label.config(text="Break", fg="#FF6F61") elif reps % 2 == 0: count_down(SHORT_BREAK_MIN * 60) title_label.config(text="Break", fg="#FF6F61") else: count_down(WORK_MIN * 60) title_label.config(text="Work", fg="#44BBA4") # ---------------------------- COUNTDOWN MECHANISM ------------------------------- # def count_down(count): minutes = math.floor(count / 60) seconds = count % 60 if seconds < 10: seconds = f"0{seconds}" canvas.itemconfig(timer_text, text=f"{minutes}:{seconds}") if count > 0: global timer timer = 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) # ---------------------------- UI SETUP ------------------------------- # window = tk.Tk() window.title("Pomodoro Timer") window.config(padx=100, pady=50, bg="#F7F7F7") title_label = tk.Label(text="Timer", fg="#375E97", bg="#F7F7F7", font=("Courier", 35, "bold")) title_label.grid(column=1, row=0) canvas = tk.Canvas(width=200, height=224, bg="#F7F7F7", highlightthickness=0) tomato_img = tk.PhotoImage(file="tomato.png") # Replace with a placeholder if needed canvas.create_image(100, 112, image=tomato_img) timer_text = canvas.create_text(100, 130, text="00:00", fill="#375E97", font=("Courier", 35, "bold")) canvas.grid(column=1, row=1) start_button = tk.Button(text="Start", highlightthickness=0, command=start_timer) start_button.grid(column=0, row=2) reset_button = tk.Button(text="Reset", highlightthickness=0, command=reset_timer) reset_button.grid(column=2, row=2) check_marks = tk.Label(fg="#44BBA4", bg="#F7F7F7", font=("Courier", 20)) check_marks.grid(column=1, row=3) window.mainloop()

Instructions:

  • Save a tomato image as tomato.png in the same directory or remove the image parts if not available.

  • Run the script.

  • Click Start to begin Pomodoro cycles.

Features:

  • Alternates between work and break intervals.

  • Shows visual check marks for completed work sessions.

  • Easy reset functionality.

Would you like a version that runs in the command line instead of a GUI?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About