💻 源代码
import tkinter as tk
import time
class Clock:
def __init__(self):
self.window = tk.Tk()
self.window.title("时钟")
self.window.geometry("300x150")
self.label = tk.Label(self.window, font=("Arial", 48, "bold"),
background="#2c3e50", foreground="white")
self.label.pack(expand=True, fill="both")
self.update_time()
self.window.mainloop()
def update_time(self):
current_time = time.strftime("%H:%M:%S")
self.label.config(text=current_time)
self.window.after(1000, self.update_time)
if __name__ == '__main__':
Clock()