Here is an example of a simple digital clock created using Python's tkinter module:
import tkinter as tk
from datetime import datetime
def time():
current_time = datetime.now().strftime("%H:%M:%S")
clock.config(text=current_time)
clock.after(1000, time)
root = tk.Tk()
root.title("Digital Clock")
clock = tk.Label(root, font=("calibri", 40, "bold"),
background = "purple",
foreground = "white")
clock.pack(expand=True)
time()
root.mainloop()This code uses the Tk() class to create a GUI window, and the Label() class to create a label that will display the current time. The time() function is used to update the label with the current time, and is called every 1000 milliseconds (1 second) using the after() method. The clock's font, background, and foreground color can be modified as per the requirement.
Comments
Post a Comment