我想让按钮首先执行一些代码,然后变得不活动一段时间,以免引起问题,但它不是执行代码然后休眠,而是只在完成休眠后执行代码,无论我以什么顺序放置代码,在这里:
def sleepsometime():
askbutton.config(state=tk.DISABLED)
cd = 5000
cmd = askbutton.config(state=tk.NORMAL)
window.after(cd, cmd)
def startstartingstartthread():
t = threading.Thread(target=start)
t.setDaemon = True
t.start()
sleepsometime()
window = tk.Tk()
window.geometry("500x500")
window.config(background="black")
window.title("NFAI Assistant")
askbutton = tk.Button(window, text="Ask", width=10, height=5, command=startstartingstartthread, foreground="black", background="cyan")
askbutton.place(x=210, y=300)
nflabel = tk.Label(window, text="Ask NFAI assistant", font=("heluvica", 30), foreground="white", background="black")
nflabel.place(x=82, y=160)
global infolabel
infolabel = nflabel = tk.Label(window, text="", font=("heluvica", 30), foreground="white", background="black")
infolabel.place(x=0, y=440)
if __name__ == '__main__':
window.mainloop()
我尝试重新安排代码和其他一些小事情,但都不起作用。 我尝试寻找答案但无济于事,也许我只是不善于寻找东西,idk
您的行:
cmd = askbutton.config(state=tk.NORMAL)
实际上执行了该函数。您想要一些可以传递给 windows.after()
的东西,它可以在超时后执行。
类似这样的:
def sleepsometime():
askbutton.config(state=tk.DISABLED)
cd = 5000
window.after(cd, lambda:askbutton.config(state=tk.NORMAL))