Build a Modern Countdown Timer with Python and Tkinter
If you want a simple, modern countdown timer for your desktop, Python’s tkinter makes it surprisingly easy to build one—with a polished interface, start/pause/reset buttons, and even a dark mode toggle. In this tutorial, we’ll build MateTools Countdown Timer, a sleek timer app step by step.
Why Build a Custom Countdown Timer?
Most timers are either:
- Too basic (just a command-line timer)
- Too bloated (complex apps with too many features)
With Python, you can create a timer that is:
- Lightweight
- Customizable
- Interactive with a modern UI
Tools and Libraries
We will use:
- Tkinter: Python’s built-in GUI toolkit
- ttk: Themed Tkinter widgets for a cleaner look
- sv_ttk: A modern light/dark theme library for Tkinter
Install sv_ttk with:
pip install sv-ttkStep 1: Setup the App Window
First, initialize the main window, set the title, size, and theme:
import tkinter as tk
from tkinter import ttk
import sv_ttkroot = tk.Tk()
root.title("MateTools - Countdown Timer")
root.geometry("900x500")
sv_ttk.set_theme("light")Step 2: Create Timer Variables
We need variables to store hours, minutes, seconds, and the time left:
hours_var = tk.StringVar(value="0")
minutes_var = tk.StringVar(value="0")
seconds_var = tk.StringVar(value="0")
time_left_var = tk.StringVar(value="00:00:00")Step 3: Build the Timer UI
The timer UI will have:
- Input fields for hours, minutes, seconds
- Time display
- Control buttons (Start, Pause, Reset)
ttk.Label(root, text="Hours:").grid(row=0, column=0)
ttk.Entry(root, textvariable=hours_var, width=5).grid(row=0, column=1)
ttk.Label(root, text="Minutes:").grid(row=0, column=2)
ttk.Entry(root, textvariable=minutes_var, width=5).grid(row=0, column=3)
ttk.Label(root, text="Seconds:").grid(row=0, column=4)
ttk.Entry(root, textvariable=seconds_var, width=5).grid(row=0, column=5)ttk.Label(root, textvariable=time_left_var, font=("Consolas", 40, "bold")).grid(row=1, column=0, columnspan=6)Get Mate Technologies’s stories in your inbox
Join Medium for free to get updates from this writer.
Step 4: Timer Logic
Here’s the countdown logic:
def update_timer_display():
time_left_var.set(f"{int(hours_var.get()):02d}:{int(minutes_var.get()):02d}:{int(seconds_var.get()):02d}")timer_running = Falsedef countdown():
global timer_running
if not timer_running:
return
h, m, s = int(hours_var.get()), int(minutes_var.get()), int(seconds_var.get())
total_seconds = h*3600 + m*60 + s
if total_seconds <= 0:
timer_running = False
tk.messagebox.showinfo("Time's up!", "Countdown finished.")
return
total_seconds -= 1
hours_var.set(str(total_seconds // 3600))
minutes_var.set(str((total_seconds % 3600) // 60))
seconds_var.set(str(total_seconds % 60))
update_timer_display()
root.after(1000, countdown)
Step 5: Control Buttons
Add Start, Pause, and Reset functionality:
def start_timer():
global timer_running
timer_running = True
countdown()def pause_timer():
global timer_running
timer_running = Falsedef reset_timer():
global timer_running
timer_running = False
hours_var.set("0")
minutes_var.set("0")
seconds_var.set("0")
update_timer_display()
And link them to buttons:
ttk.Button(root, text="Start", command=start_timer).grid(row=2, column=0)
ttk.Button(root, text="Pause", command=pause_timer).grid(row=2, column=1)
ttk.Button(root, text="Reset", command=reset_timer).grid(row=2, column=2)Step 6: Dark/Light Mode
Switch between themes with a simple checkbox:
dark_mode_var = tk.BooleanVar(value=False)def toggle_theme():
if dark_mode_var.get():
sv_ttk.set_theme("dark")
else:
sv_ttk.set_theme("light")ttk.Checkbutton(root, text="Dark Mode", variable=dark_mode_var, command=toggle_theme).grid(row=3, column=0, columnspan=3)
Step 7: Run the App
Finally, initialize the display and start the Tkinter main loop:
update_timer_display()
root.mainloop()Screenshot / Demo
(Include a screenshot of your app here if possible)
Key Features Recap
- Flexible input for hours, minutes, and seconds
- Start / Pause / Reset controls
- Dark / Light theme toggle
- Live countdown display
Conclusion
With just a few lines of Python and tkinter, you can build a beautiful, functional countdown timer. This project is perfect for:
- Timeboxing work sessions
- Cooking timers
- Pomodoro productivity
Experiment with themes, fonts, and layouts to make it truly yours.








