Creating a Basic Digital Clock using Python | Easy GUI Project for Beginners #shorts

Posted by

Python Time: Building a Minimalist Digital Clock

Python Time: Building a Minimalist Digital Clock

Are you a beginner in Python looking for a simple GUI project to practice your skills? Look no further than building a minimalist digital clock using Python!

Getting Started

Before we dive into the code, make sure you have Python installed on your computer. You can download it from the official Python website if you haven’t already.

Creating the GUI

We will be using the tkinter library to create the GUI for our digital clock. You can start by importing the necessary modules:


import tkinter as tk
from time import strftime

Next, we will create a window for our clock:


root = tk.Tk()
root.title("Minimalist Digital Clock")

Displaying the Time

Now, let’s create a label to display the current time:


def time():
string = strftime('%H:%M:%S %p')
lbl.config(text = string)
lbl.after(1000, time)

lbl = tk.Label(root, font = ('calibri', 40, 'bold'), background = 'black', foreground = 'white')
lbl.pack(anchor = 'center')
time()

Running the Clock

Finally, we will run the clock by calling the main loop:


root.mainloop()

And that’s it! You now have a minimalist digital clock built using Python. This project is a great way to practice your Python skills while creating something practical.

#shorts

0 0 votes
Article Rating
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@user-tc2fk5wr3c
2 months ago

❤❤

@jayanthabulugahamulla889
2 months ago

Ela bn❤