The Wayback Machine - https://web.archive.org/web/20240906230701/https://www.geeksforgeeks.org/python-create-a-digital-clock-using-tkinter/
Open In App

Python | Create a digital clock using Tkinter

Last Updated : 25 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 

Prerequisites: 

  • 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: 
 

Python3




# 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()
root.title('Clock')
 
# 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')
time()
 
mainloop()


Output: 
 

Code Explanation:

  1. The code starts by importing the necessary modules.
  2. The first module is the tkinter library, which provides basic functionality for creating graphical user interfaces (GUIs).
  3. Next, the strftime function is imported to retrieve system time.
  4. Next, a window is created and given a title of “Clock.”
  5. A function called time() is then created to display the current time on the label widget.
  6. This function uses the strftime() function to format the time string according to system conventions.
  7. The last part of this code sets up styling for the label widget so that it will look nicer.
  8. Finally, an instance of Label is created and placed at the center of the window.
  9. The time() function is executed, and your output should look like this: Clock: Tue Dec 12 08:00:00 2016
  10. The code creates a window and assigns it the title “Clock”.
  11. The time() function is then called to display the current time on the label widget.
  12. The lbl.config() function is used to set the text of the label widget.
  13. The after() function is used to delay displaying the time for 1000 milliseconds.
  14. Finally, the style of the label widget is modified with lbl.pack().

Previous Article
Next Article

Similar Reads

Create an Alarm Clock using Tkinter
Prerequisite: Python GUI – tkinter, winsound, time, and datetime. As we all know, nowadays wake up on time is a very difficult task. The solution is the Alarm Clock. In this article, we will learn, How to create an Alarm Clock using Tkinter in Python. Without alarms, several people would oversleep and land up late for work. Alarm clocks may also be
4 min read
Create digital clock using Python-Turtle
Turtle is a special feature of Python. Using Turtle, we can easily draw on a drawing board. First, we import the turtle module. Then create a window, next we create a turtle object and using the turtle methods we can draw in the drawing board. Prerequisites: Turtle Programming in Python Installation: To install this module type the below command in
3 min read
PyQt5 - Create a digital clock
In this article we will see how to create a digital clock using PyQt5, this digital clock will basically tells the current time in the 24 hour format. In order to create a digital clock we have to do the following: Create a vertical layoutCreate label to show the current time and put it in the layout and align it to the center.Create a QTimer objec
3 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Python | Create a stopwatch using clock object in kivy using .kv file
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop applications. Kivy Tutorial - Learn Kivy with Examples. Clock Object: The Clock object allows you to schedule a function call in
6 min read
Python | Create a stopwatch Using Clock Object in kivy
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop applications.In this, we are going to see how can we create a stopwatch using a label. In the code, we will be creating just a c
4 min read
Create Analog Clock using PyQt5 in Python
Prerequisite: Introduction to pyqt-5 A clock or watch is called "analog" when it has moving hands and (usually) hours marked from number 1 to 12 to show you the time. Some have Roman Numerals (I, II, III, etc) instead, or no numbers at all! In other words: not a digital clock. PyQt5 is a cross-platform GUI toolkit, a set of python bindings for Qt v
3 min read
Create Health Clock for programmers using Python
In this article, we will be creating a Python script that takes care of the health of a person, especially a programmer. It will remind the user to drink water, do an eye exercise, and do a physical exercise at different specified time intervals. It will also keep a log of time at which the exercises are done, water is drunk as well as the no of ex
9 min read
Python Tkinter | Create different type of lines using Canvas class
In Tkinter, Canvas.create_line() method is used to create lines in any canvas. These lines can only be seen on canvas so first, you need to create a Canvas object and later pack it into the main window. Syntax: Canvas.create_line(x1, y1, x2, y2, ...., options = ...) Note: Minimum of 4 points are required to create a line, but you can also add multi
2 min read
Python Tkinter | Create different shapes using Canvas class
In Tkinter, Canvas class is used to create different shapes with the help of some functions which are defined under Canvas class. Any shape that Canvas class creates requires a canvas, so before creating any shapes a Canvas object is required and needs to be packed to the main window. Canvas Methods for shapes: Canvas.create_oval(x1, y1, x2, y2, op
3 min read
Python | Create a GUI Marksheet using Tkinter
Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface. Refer the below articles to get the idea about basics of t
8 min read
Create a Yes/No Message Box in Python using tkinter
Python offers a number Graphical User Interface(GUI) framework but Tk interface or tkinter is the most widely used framework. It is cross-platform which allows the same code to be run irrespective of the OS platform (Windows, Linux or macOS). Tkinter is lightweight, faster and simple to work with. Tkinter provides a variety of widgets that can be c
4 min read
Create MySQL Database Login Page in Python using Tkinter
Prerequisites: Python GUI – tkinter, Python MySQL – Select QueryTkinter is one of the Python libraries which contains many functions for the development of graphic user interface pages and windows. Login pages are important for the development of any kind of mobile or web application. This page is most essential for user authentication purposes.We
2 min read
Create Copy-Move GUI using Tkinter in Python
Everyone reading this post is well aware of the importance of Copying the file or moving the file from one specific location to another. In this post, we have tried to explain not only the program but added some exciting pieces of Interface. Up to now, many of you may get about what we are talking about. Yes, you are right, We are going to use "Tki
4 min read
Create Countdown Timer using Python-Tkinter
Prerequisites: Python GUI – tkinterPython 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.Approach Importing the module – tkinter, timeCrea
2 min read
Create a Pomodoro Using Python Tkinter
In this article, we are going to see how to create a Pomodoro using Python Tkinter. Why Pomodoro? Concentrating on studies or work is the most essential part of Time management. We always mess up time management when it comes to focusing on work. Fortunately, you can manage your time by focusing on your work and then taking a short break to relax.
4 min read
Create Address Book in Python - Using Tkinter
Prerequisite: Tkinter In this article, we will discuss how to create an address book in Tkinter using Python. Step by step implementation: Step 1: Creating GUI. In this, we will add all the GUI Components like labels, text area and buttons. C/C++ Code # Import Module from tkinter import * # Create Object root = Tk() # Set geometry root.geometry('40
3 min read
Create First GUI Application using Python-Tkinter
We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter. What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python sta
12 min read
Draw Clock Design using Turtle in Python
Prerequisites: Turtle Programming in Python Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. To draw Clock Design : Following steps are used : Import turtl
2 min read
Clock App with Kivy using Python
In this article, we are going to see how to develop a Clock Application with Kivy using Python. Kivy is a graphical user interface opensource Python library that allows you to develop multi-platform applications on Windows, macOS, Android, iOS, Linux, and Raspberry-Pi. In addition to the regular mouse and keyboard inputs, it also supports multitouc
4 min read
Create Table Using Tkinter
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task
3 min read
Create a GUI to check Domain Availability using Tkinter
There might be a case where a user wants to create a website and having certain ideas for the website's name but is struck on their availability. So let's develop a GUI that will check for domain availability. We will use the Python-whois module to get information about the website. It's able to extract data for all the popular TLDs (com, org, net,
2 min read
Create a GUI to Get Domain Information Using Tkinter
Prerequisites: Python GUI – tkinter Domain information is very important for every user. It contains information like Name, organization, State, city, Ip address, emails, server name, etc. In this article, we will write code for getting domain information and bind it with GUI Application. We will use the Python-whois module to get information about
2 min read
How to create a Splash Screen using Tkinter?
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Prerequisite: Python GUI – tkinter What is a Splash Screen? A splash screen in tkinter is a tkinter window that disappears
4 min read
Create Multiple frames with Grid manager using Tkinter
Prerequisites: Tkinter Tkinter can support the creation of more than one widget in the same frame. Not just this it also supports a mechanism to align them relative to each other. One of the easiest ways of aligning the different widgets in the Tkinter is through grid manager. Apart from aligning various widgets, the grid manager can also be used f
2 min read
Build a Clock Application using Django and React
The clock project aims to develop a simple yet functional clock application using modern web technologies. It combines the frontend capabilities of React.js for creating dynamic user interfaces with the styling power of Tailwind CSS for a sleek and responsive design. Additionally, the backend is built using Django, providing a robust framework for
4 min read
Python Tkinter | Create LabelFrame and add widgets to it
Tkinter is a Python module which is used to create GUI (Graphical User Interface) applications. It is a widely used module which comes along with the Python. It consists of various types of widgets which can be used to make GUI more user-friendly and attractive as well as functionality can be increased. LabelFrame can be created as follows: -> i
2 min read
How to create a pop up message when a button is pressed in Python - Tkinter?
In this article, we will see how to create a button and how to show a popup message when a button is pressed in Python. Tkinter is a standard Python Package for creating GUI applications. Tkinter may be a set of wrappers that implement the Tk widgets as Python classes. Python, when combined with Tkinter, provides a quick and straightforward way to
2 min read
Python Tkinter - Create Button Widget
The Tkinter Button widget is a graphical control element used in Python's Tkinter library to create clickable buttons in a graphical user interface (GUI). It provides a way for users to trigger actions or events when clicked. Note: For more reference, you can read our article: What is WidgetsPython Tkinter OverviewPython Tkinter TutorialTkinter But
6 min read
Python | time.clock() method
Time module in Python provides various time related functions. time.clock() method of time module in Python is used to get the current processor time as a floating point number expressed in seconds. As, Most of the functions defined in time module call corresponding C library function. time.clock() method also call C library function of the same na
3 min read
Practice Tags :