时钟实例
from tkinter import *
from time import strftime
root = Tk()
root.title('时钟')
lbl = Label(root, font = ('arial',300,'bold'), bg = 'black', fg = 'white')
lbl.pack(anchor = 'center', fill = 'both', expand = 1)
mode = 'hour'
def showtime():
if mode == 'hour':
string = strftime('%H:%M:%S %p')
else:
string = strftime("%Y-%m-%d")
lbl.config(text=string)
lbl.after(1000,showtime) # 1秒后执行 time 函数
def mouse_click(event):
global mode
if mode == 'hour':
mode = 'day'
else:
mode = 'hour'
print(mode)
lbl.bind("<Button>", mouse_click)
showtime()
mainloop()