Skip to content
Related Articles
Open in App
Not now

Related Articles

Create Countdown Timer using Python-Tkinter

Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 20 Jan, 2022
Improve Article
Save Article
Like Article

Prerequisites: Python GUI – tkinter
Python Tkinter is a GUI programming package or built-in library. Tkinter provides the Tk GUI toolkit with a potent object-oriented interface. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.

  1. Importing the module – tkinter, time
  2. Create the main window (container)
  3. Add number of widgets to the main window:Button, Entry
  4. Apply the event Trigger on the widgets.

Below is the implementation. 


import time
from tkinter import *
from tkinter import messagebox
# creating Tk window
root = Tk()
# setting geometry of tk window
# Using title() to display a message in
# the dialogue box of the message in the
# title bar.
root.title("Time Counter")
# Declaration of variables
# setting the default value as 0
# Use of Entry class to take input from the user
hourEntry= Entry(root, width=3, font=("Arial",18,""),
minuteEntry= Entry(root, width=3, font=("Arial",18,""),
secondEntry= Entry(root, width=3, font=("Arial",18,""),
def submit():
        # the input provided by the user is
        # stored in here :temp
        temp = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
        print("Please input the right value")
    while temp >-1:
        # divmod(firstvalue = temp//60, secondvalue = temp%60)
        mins,secs = divmod(temp,60)
        # Converting the input entered in mins or secs to hours,
        # mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
        # 50min: 0sec)
        if mins >60:
            # divmod(firstvalue = temp//60, secondvalue
            # = temp%60)
            hours, mins = divmod(mins, 60)
        # using format () method to store the value up to
        # two decimal places
        # updating the GUI window after decrementing the
        # temp value every time
        # when temp value = 0; then a messagebox pop's up
        # with a message:"Time's up"
        if (temp == 0):
            messagebox.showinfo("Time Countdown", "Time's up ")
        # after every one sec the value of temp will be decremented
        # by one
        temp -= 1
# button widget
btn = Button(root, text='Set Time Countdown', bd='5',
             command= submit) = 70,y = 120)
# infinite loop which is required to
# run tkinter program infinitely
# until an interrupt occurs



My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!