This project is a simple digital clock application built using Python’s Tkinter library. The clock displays the current time in hours, minutes, and seconds, updating every second. This project serves as an introduction to GUI programming in Python and provides a basic understanding of how to create and manipulate graphical elements.
By completing this project, you will learn how to:
To run this project on your machine, ensure you have Python installed. Follow these steps:
from tkinter import Label, Tk
import time
app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("420x150")
app_window.resizable(1,1)
text_font= ("Boulder", 68, 'bold')
background = "#f2e750"
foreground= "#363529"
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()
from tkinter import Label, Tk
import time
app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("420x150")
app_window.resizable(1,1)
text_font= ("Boulder", 68, 'bold')
background = "#f2e750"
foreground= "#363529"
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()
1. Import necessary libraries.
2. Create the main application window.
3. Set window properties (title, size, resizability).
4. Define the label to display the time with desired font and style.
5. Create a function to get the current time and update the label text.
6. Use the after() method to repeatedly call the update function.
7. Start the Tkinter main event loop.
1. Import necessary libraries.
2. Create the main application window.
3. Set window properties (title, size, resizability).
4. Define the label to display the time with desired font and style.
5. Create a function to get the current time and update the label text.
6. Use the after() method to repeatedly call the update function.
7. Start the Tkinter main event loop.
Q1: Can I change the time format to 12-hour?
Yes, modify the time_live line in the digital_clock function as follows:
time_live = time.strftime(“%I:%M:%S %p”)
Q2: How can I customize the font and colors?
You can change the text_font, background, and foreground variables to your preferred values.
Q3: What if the clock does not update?
Ensure the after() method is correctly set to call the digital_clock function repeatedly. Double-check the time interval is appropriate (200 milliseconds for a smooth update).
Office:- 660, Sector 14A, Vasundhara, Ghaziabad, Uttar Pradesh - 201012, India