GUI Digital Clock Using Python with Source Code
Introduction:
In this Project, I will show you. How to Create Graphical User Interface of Digital Clock and How to Design your clock beautifully. We are Using Tkinter, which is a framework of Python Programming Language. In which we can design your outer part of the project or an application. tkinter mainly provides a good user experience and is understandable by a non-technical person easily.
Now we start work with Tkinter for creating our digital clock. In this project, we can customize the background, font, etc. As your need.
A digital clock is a type of clock that displays the time digitally (i.e. in numerals or other symbols). We get time from CLI ( Command Line Interface) but that is not much attractive GUI( Graphical User Interface) is much more attractive as well interactive. Now we build a GUI of a digital clock in python implemented using Tkinter & Time packages/module. Before writing code some requirements for GUI
Import Tkinter:
First, we need to install the Tkinter module. If you do not have this module already installed in your system then you can install the same using the pip package manager:
C:\User\admin> pip install tkinter
How To Run The Code :
Step 1: Open any Python Code Editor
Step 2: Make a Python file digital-clock.py
Step 3: Copy the code & Paste it
Step 4: Run the file digital-clock.py and your Program will run
Source Code:
# importing whole module------
from tkinter import *
# importing strftime function to capturing system's time
from time import strftime
# creating tkinter window
digital_clock = Tk()
digital_clock.geometry("600x300")
digital_clock.title('Digital Clock')
# Display time on the label using this function
def time():
string = strftime('%H:%M:%S %p') # %h=hour ,%M=Minute ,%S=second ,p%=am or pm according to the given time value
lable.config(text = string)
lable.after(1000, time)
#Increase the user experience designning the label widget
lable = Label(digital_clock, font = ('calibri', 40, 'bold'),
background = '#AA0000',
foreground = 'white')
# clock at the centre of the tkinter window
lable.pack(anchor = 'center')
time() #function calling
mainloop()
Explanation:
Step 1: Firstly import Tkinter & strftime from time
Step 2: Create Tkinter window & give the title
Step 3: Define the label font, background, foreground
Step 4: Pack the label at the center using anchor
Step 5: Create a function in which string store hour, Minute, Second, AM, or PM
Step 6: Config text to string & define microsecond
Step 7: Call the function
Output:
Find More Projects
Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …
Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …
Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …
Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …
Digital and Analog Clock using HTML CSS and JavaScript Introduction : This project is a digital clock and stopwatch system, which allows …
Coffee Shop Website using HTML, CSS & JavaScript Introduction : This project is a website for coffee house business. It uses HTML …