Create a Digital Clock in Python
In today's fast-paced digital world, creating a digital clock in Python can be a fun and educational project. Whether you're a beginner looking to improve your Python skills or an experienced programmer exploring new possibilities, building a digital clock is a practical and rewarding endeavor. In this tutorial, we'll walk you through the process of creating a digital clock using Python.
The clock should look like the one below:
Here's the Python code that creates and displays a digital clock using Python's built-in modules, including tkinter for the graphical user interface and time to fetch the current time:
from tkinter import Tk, Label, BOTTOM, mainloop
from time import strftime
root = Tk()
root.geometry("500x200")
root.title('Python Clock')
Label(root, font='arial 20 bold').pack(side=BOTTOM)
def time():
string = strftime('%H:%M:%S %p')
mark.config(text=string)
mark.after(1000, time)
mark = Label(root,
font=('calibri', 50, 'bold'),
pady=720,
foreground='black')
mark.pack(anchor='center')
time()
mainloop()