0% found this document useful (0 votes)
41 views

Project Assignment

This document describes a project to create a digital clock application using Python. It includes importing necessary libraries like Tkinter and time. It defines the window properties, font, colors, and border. It displays the live time in hours:minutes:seconds format by configuring the label text and updating it every 200 milliseconds using the after() method. Running the digital_clock() function and mainloop() displays the continuously updating digital clock.

Uploaded by

Waseem Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Project Assignment

This document describes a project to create a digital clock application using Python. It includes importing necessary libraries like Tkinter and time. It defines the window properties, font, colors, and border. It displays the live time in hours:minutes:seconds format by configuring the label text and updating it every 200 milliseconds using the after() method. Running the digital_clock() function and mainloop() displays the continuously updating digital clock.

Uploaded by

Waseem Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Project

Submitted to: Sir Gulraiz Javed


Section: (E2)

Semester: 1st
Subject: Programming Fundamental (Python)
Department: Software Engineering
Names of Students Roll No
M Waseem Hassan (G.L) F22BSEEN1E02101
Muhammad Arif F22BSEEN1E02102
Sami Ul Rehman F22BSEEN1E02100
Digital Clock with Python
In this section, I will show you how to create a digital clock using
python. This is a simple task to get started with the Tkinter library in
Python, which is a built-in package that comes with Python. Tkinter has
some cool features that can be used to build simple apps.
Explanation:
Now let’s see how to create a digital clock GUI application with Python.
I will first start with importing the libraries:
from tkinter import Label, Tk
import time
Now let’s define the title and size of our application. Note that in the
code below I will set both the height and width of the resizable function
as True(1,1) if you want a fixed window and don’t want to maximize or
minimize the output you can set it to False(0,0):
app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("420x150")
app_window.resizable(1,1)

Now here I will define the font of the time and its colour, its border width
and the background colour of the digital clock:
text_font= ("Boulder", 68, 'bold')
background = "#f2e750"
foreground= "#363529"
border_width = 25

Now here I will combine all the elements to define the label of the
clock application:
label = Label(app_window, font=text_font, bg=background, fg=foreground, bd=border_width)
label.grid(row=0, column=1)

Now let’s define the main function of our digital clock. Here I will set
the text of the label as the realtime:
def digital_clock():
time_live = time.strftime("%H:%M:%S")
label.config(text=time_live)
label.after(200, digital_clock)

Now let’s run and see our output:


digital_clock()
app_window.mainloop()

Output
Hierarchy chart
From Tkinter import label.TK

Import Time

opp_window = TK Text_font=(“Boulder” Label(app_window) Time_live=time Digital_clock()


,68, ‘bold’)

app_window.title fg=foreground,border Label.config(text)


(“Digital Clock”) Background=“white” App_window.
mainloop()
Label.grid() Label.after(200
app_window.geometry Foreground=“red” ,digital_clock)
(“420 150”)

Border_width=25
app_window.resizable
(1,1)
Flow Chart
Start

Import time
Size of digital clock(“420 150”)

Font color and window color


Border_width=25

Show_live=time
(“%H.%M.%S”)

End
Full Code
from tkinter import Label, Tk
import time
app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("850x500")
app_window.resizable(1,1)

text_font= ("Boulder", 120, 'bold')


background = "#c0c0c0"
foreground= "#FF0000"
border_width = 25
label = Label(app_window, font=text_font, bg=background, 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()

You might also like