Digital Clock – Python Source Code

  • Code With GUI
Python
# import required modules
import tkinter as tk
import time

# Creating date and time function
def digital_clock():
    current_time = time.strftime('%H:%M:%S %p')
    current_date_day = time.strftime('%Y-%m-%d, %A')
    
    # Combine time and date/day
    time_date_day_label.config(text=current_time + '\n' + current_date_day)  
    
    # Update every 1000ms (1 second)
    time_date_day_label.after(1000, digital_clock)  

# Create the main application window
root = tk.Tk()
root.title("Digital Clock")
root.geometry("450x200")
root.configure(bg="black") 

# Create a label to display the time and date
time_date_day_label = tk.Label(root, text="", font="arial 30 bold", fg="red", bg="black")
time_date_day_label.pack(padx=30, pady=40)

# Calling the digital clock function
digital_clock()

# Run the main loop
root.mainloop()

# Digital Clock Source Code - By Codotix

Leave a Comment

Your email address will not be published. Required fields are marked *