Skip to content
Related Articles

Related Articles

Python | Create a digital clock using Tkinter
  • Difficulty Level : Easy
  • Last Updated : 12 Apr, 2019

As we know Tkinter is used to create a variety of GUI (Graphical User Interface) applications. In this article we will learn how to create a Digital clock using Tkinter.

-> Python functions
-> Tkinter basics (Label Widget)
-> Time module

Using Label widget from Tkinter and time module :
In the following application, we are going to use Label widget and also going to use time module which we will use to retrieve system’s time.

Below is the implementation:

# importing whole module
from tkinter import * 
from tkinter.ttk import *
# importing strftime function to
# retrieve system's time
from time import strftime
# creating tkinter window
root = Tk()
# This function is used to 
# display time on the label
def time():
    string = strftime('%H:%M:%S %p')
    lbl.config(text = string)
    lbl.after(1000, time)
# Styling the label widget so that clock
# will look more attractive
lbl = Label(root, font = ('calibri', 40, 'bold'),
            background = 'purple',
            foreground = 'white')
# Placing clock at the centre
# of the tkinter window
lbl.pack(anchor = 'center')


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :