tk库实现倒计时,效果如下
from tkinter import * #导入模块 import time guo=Tk() #创建跟窗口 guo.title('倒计时') #设置标题 guo.geometry('200x200') #设置大小 l1=Label(text='请输入倒计时') #创建一个标签 l1.pack() text1=Entry() #创建一个单行文本框 text1.pack() def pa(): #数据代码 a=int(text1.get()) for i in range(1, a + 1): l1.config(text=f'剩余时间:{a - i + 1}秒') time.sleep(1) guo.update() #更新函数 Button(text='开始',command=pa).pack()#按钮 guo.mainloop()