Python Digital Clock application

Published February 03, 2022

We will create a digital clock application using the Python Tkinter library in this post. Python Tkinter library comes with an in-built package that comes with cool features to create simple applications.

Let's see how to create a digital clock application in Python using Tkinter. Here are the steps:

Step 1:  import all the required libraries.

from tkinter import Label, Tk

import time

Step 2: Design the GUI of our application. Define the title and size of the application. Also, define the font and size of the digital clock.

app_window = Tk()

app_window.title(" Python Digital Clock App")

app_window.geometry("420x150")

app_window.resizable(1,1)

text_font= ("Arial", 32, 'bold')

foreground= "#363529"

border_width = 25

label = Label(app_window, font=text_font, fg=foreground, bd=border_width)

label.grid(row=0, column=1)

Step 3:  We will now create the main function for the digital clock application and set the label text as the real-time.

def digital_clock():

   time_live = time.strftime("%H:%M:%S")

   label.config(text=time_live)

   label.after(200, digital_clock)

digital_clock()

Step 4: Now run the application and see what it outputs

 

Complete code Python Digital Clock

from tkinter import Label, Tk

import time

app_window = Tk()

app_window.title(" Python Digital Clock App")

app_window.geometry("420x150")

app_window.resizable(1,1)

text_font= ("Arial", 32, 'bold')

foreground= "#363529"

border_width = 25

label = Label(app_window, font=text_font, fg=foreground, bd=border_width)

label.grid(row=0, column=1)

def digital_clock():

   time_live = time.strftime("%H:%M:%S")

   label.config(text=time_live)

   label.after(200, digital_clock)

digital_clock()

app_window.mainloop()

 

Python Digital clock with tkinter

 

Conclusion: In this Python example tutorial we covered how to create digital clock

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

241 Views