如何在tkinter中禁用按钮中间程序?

2024-10-05 22:01:52 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有一个按钮,button = Button(root, text="Hello", command = somecommand),如果某个条件在程序中间是真的,我想禁用它。这是我的代码:

from tkinter import *
root=Tk()
def hi():
    print("hi")
button=Button(root,text="Say hello",command=hi)
button.pack()
while 1:
    root.update_idletasks()
    root.update()
    if 1==1:
        #disable button here

谢谢!在


Tags: 代码textfromhellotkinterupdatebuttonroot
1条回答
网友
1楼 · 发布于 2024-10-05 22:01:52

将此reference作为书签(不完美,但非常有用)。Button page表示“state:将此选项设置为”tk禁用使按钮变灰并使其无响应。有价值tk.激活当鼠标在上面的时候。默认为tk.正常. ". 换句话说,button['state'] = DISABLED和{}将取消激活并恢复{}。在

相关问题 更多 >