点完按钮后不显示“(x)秒后重试”
只在最后闪一下
代码:
import tkinter as tk
from time import sleep
i = 5
def setdisabled():
global i
if i != 0:
a = '(' + str(i) + 's)后重试'
# btn.config(textvariable = a,state = tk.DISABLED,bg="#ccc")
btn.config(text = a,state = tk.DISABLED,bg="#ccc")
i -= 1
sleep(1)
root.after(100,setnormal)
def setnormal():
btn.config(text = '获取验证码',state = tk.NORMAL,bg = "#090")
root = tk.Tk()
btn = tk.Button(root,text = '获取验证码',command = setdisabled,bg = "#090")
btn.pack()
root.mainloop()
python版本:3.8