Digital Clock with Python : Learn to Code

16 comments

https://images.ecency.com/DQmSRCHW1LxHTfbsHcTX5xDKiCNmBt1esaoQtXLNCkkfP6j/image.png

DigitalClock.py

import tkinter as tk
from tkinter import Label
import time

# Create the main window
root = tk.Tk()
root.title("Digital Clock")

# Define the clock function
def clock():
    # Get the current time
    current_time = time.strftime("%H:%M:%S %p")
    # Update the label with the current time
    clock_label.config(text=current_time)
    # Call the clock function after 1000ms (1 second)
    clock_label.after(1000, clock)

# Create a label to display the time
clock_label = Label(root, font=('calibri', 40, 'bold'), background='purple', foreground='white')
clock_label.pack(anchor='center')

# Call the clock function to update the time
clock()

# Start the main loop
root.mainloop()


Comments

Sort byBest