How to Create Digital Clock Using Python Tkinter

In this Python tutorial, we will see how to create a digital clock using python turtle. This digital clock can be created with the help of Graphical User interface application. This tkinter is used to create a variety of GUI( Graphical User Interface) application.

How to create digital clock using Python Tkinter

Here we are creating the digital clock for this we are using the label widget and the time module that is used to recover the system time and created a digital clock with a beautiful background and foreground color.

Block of Code:

In this Python tkinter block of code we are importing all the necessary library. Here firstly we are importing the tkinter library that gives the functionality for building the graphical user interface and using the strftime function that is imported for recovering the system time.

#How to create digital clock using Python Tkinter
# importing whole module
from tkinter import *
from tkinter.ttk import *

# importing strftime function to recover the system's time
from time import strftime
 

Check this code in the Repository from Github and you can also fork this code.

Github User Name: PythonT-Point

Block of Code:

In this python tkinter block of code, here we are creating a window and give the title to the window as Pythontpoint and then creating a function called time that is used to display the current time on the label widget.

After that uses the strftime() function that form the time string according to the system convention.

#How to create digital clock using Python Tkinter
# creating tkinter window
ws = Tk()
ws.title('Pythontpoint')
 
# This function is used to display the time on the label
 
def digitalclocktime():
    strng = strftime('%H:%M:%S %p')
    label.config(text=strng)
    label.after(1000, digitalclocktime)

Block of Code:

In this block of code we are describing the styling for the label widget that give the window a style and the clock look attractive.

Here the sample of the label is created and it is placed at the center of the window. The time() function is executed and the digital clock is created.

The whole code creates a window and the title is also given to the window. The time() function is also called to show current time on the label widget.

In this code we are using the after() function that is used to delay the displaying time for 100 milliseconds and also giving the style to the widget that is modified by label.pack()

# Style the label widget so that clock will look more attractive
label = Label(ws, font=('Times New Roman', 50, 'bold'),
            background='cyan',
            foreground='white')
# Place the clock at the center of the tkinter window
label.pack(anchor='center')
digitalclocktime()
 
mainloop()

Code:

Hereafter splitting the code and explaining how to create digital clock using Python, now we will see how the output look like after running the whole code.

# How to create digital clock using Python Tkinter
# importing whole module
from tkinter import *
from tkinter.ttk import *
 
# importing strftime function to recover the system's time
from time import strftime
 
# creating tkinter window
ws = Tk()
ws.title('Pythontpoint')
 
# This function is used to display the time on the label
 
def digitalclocktime():
    strng = strftime('%H:%M:%S %p')
    label.config(text=strng)
    label.after(100, digitalclocktime)
 
 
# Style the label widget so that clock will look more attractive
label = Label(ws, font=('Times New Roman', 50, 'bold'),
            background='cyan',
            foreground='white')
 
# Place the clock at the center of the tkinter window
label.pack(anchor='center')
digitalclocktime()
 
mainloop()

Output:

After running the whole code we get the following output in which we can see that the digital clock is created and generated the exact time as a clock. Here we are creating a window and give the title to the window as Pythontpoint and then creating a function called time that is used to display the current time on the label widget.

How to create digital clock using python tkinter
How to create digital clock using Python Tkinter

So, in this tutorial, we have illustrated How to create digital clock using Python Tkinter. Moreover, we have also discussed the whole code used in this tutorial.

Read some more tutorials related to Python Tkinter

Python Tkinter temperature converter

Python Tkinter Todo List

Python Tkinter Simple Calculator

Stone Paper Scissor using Python Tkinter

Python Tkinter Color Game

Python Tkinter Instagram User Detail

119 thoughts on “How to Create Digital Clock Using Python Tkinter”

  1. I truly relished the effort you’ve put in here. The sketch is stylish, your authored material chic, however, you seem to have developed some anxiety about what you intend to deliver subsequently. Assuredly, I will revisit more regularly, akin to I have nearly all the time, in the event you maintain this rise.

    Reply
  2. The breadth of knowledge compiled on this website is astounding. Every article is a well-crafted masterpiece brimming with insights. I’m grateful to have discovered such a rich educational resource. You’ve gained a lifelong fan!

    Reply
  3. I was just as enthralled by your work as you were. Your sketch is elegant, and your written content is sophisticated. However, you seem concerned about potentially delivering something questionable soon. I’m confident you’ll resolve this issue quickly and return to your usual high standards.

    Reply
  4. Your work has captivated me just as much as it has you. The sketch you’ve created is tasteful, and the material you’ve written is impressive. However, you seem anxious about the prospect of presenting something that could be considered questionable. I believe you’ll be able to rectify this situation in a timely manner.

    Reply
  5. I loved as much as you will receive carried out right here The sketch is tasteful your authored subject matter stylish nonetheless you command get got an edginess over that you wish be delivering the following unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike

    Reply
  6. My admiration for your creations is as substantial as your own sentiment. The visual presentation is tasteful, and the written content is sophisticated. Yet, you seem uneasy about the possibility of presenting something that may cause unease. I’m confident you’ll be able to resolve this issue efficiently.

    Reply
  7. The degree to which I appreciate your creations is equal to your own sentiment. Your sketch is tasteful, and the authored material is stylish. Yet, you seem uneasy about the prospect of embarking on something that may cause unease. I agree that you’ll be able to address this matter efficiently.

    Reply
  8. Fourweekmba You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!

    Reply
  9. I loved as much as youll receive carried out right here The sketch is tasteful your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike

    Reply
  10. What i do not realize is in fact how you are no longer actually much more wellfavored than you might be right now Youre very intelligent You recognize thus considerably in relation to this topic made me in my view believe it from numerous numerous angles Its like men and women are not fascinated until it is one thing to do with Lady gaga Your own stuffs excellent All the time handle it up

    Reply
  11. Активируйте промокод ANDROID777 для 7k Casino и скачайте APK через официальный телеграм канал https://t.me/casino_7kk

    Reply
  12. Keep up the fantastic work! Kalorifer Sobası odun, kömür, pelet gibi yakıtlarla çalışan ve ısıtma işlevi gören bir soba türüdür. Kalorifer Sobası içindeki yakıtın yanmasıyla oluşan ısıyı doğrudan çevresine yayar ve aynı zamanda suyun ısınmasını sağlar.

    Reply
  13. It’s the best time to make a few plans for the
    future and it is time to be happy. I’ve learn this publish and if I may I want to counsel
    you some attention-grabbing issues or advice. Maybe you could write next articles referring to this article.
    I want to read more issues about it!!

    Reply
  14. Hello! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to
    get my site to rank for some targeted keywords but I’m not seeing very good results.

    If you know of any please share. Thank you! I saw similar article here:
    Warm blankets

    Reply
  15. Sugar defender As someone that’s always bewared regarding my blood sugar, finding Sugar Defender has actually been a
    relief. I really feel so much more in control, and my current examinations have revealed favorable enhancements.
    Understanding I have a dependable supplement to support my
    regular gives me assurance. I’m so thankful for Sugar Protector’s impact on my wellness!

    Reply

Leave a Comment