数字时钟界面之Tkinter实现
单击界面 切换模式 显示具体的时间将切换为年月日程序代码
from tkinter import *
from time import strftime
root = Tk()
root.geometry('500x300')
lb = Label(root,font=('微软雅黑',32),bg='lightblue',fg='black')
lb.pack(anchor='center',fill=BOTH,expand=1)
# 定义mode标志
time = 'mode'
# 定义显示日期/时间的函数
def time_func():
if time == 'mode':
time1 = strftime('%H:%M:%S:%p')
else:
time1 = strftime('%Y-%m-%d')
lb.config(text=time1)
lb.after(1000,time_func)
def move_cursor(event):
# 需要声明time为全局变量
global time
if time == 'mode':
time = 'data'
else:
time = 'mode'
lb.bind('<Button>',move_cursor)
time_func()
root.mainloop()
来学习,多谢
谢谢楼主分享!谢谢 浪漫小流氓 发表于 2023-1-9 16:43
谢谢楼主分享!谢谢
不用谢啦{:4_257:}
乐活 发表于 2023-1-9 15:50
来学习,多谢
哈哈 不用谢{:4_263:}
谢谢分享收了
飓风861 发表于 2023-1-11 08:42
谢谢分享收了
嗯 不用谢 {:4_262:}
PYG18周年生日快乐!
页:
[1]