【问题标题】:How can you disable a button mid-program in tkinter?如何在 tkinter 中禁用按钮中间程序?
【发布时间】:2018-03-13 00:04:21
【问题描述】:

假设我有一个按钮,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

谢谢!

【问题讨论】:

标签: python button tkinter


【解决方案1】:

将此reference 加入书签(不完美,但非常有帮助)。 Button page 表示“状态:将此选项设置为 tk.DISABLED 以使按钮变灰并使其无响应。当鼠标悬停在其上时,其值为 tk.ACTIVE。默认值为 tk.NORMAL。”。换言之,button['state'] = DISABLEDbutton['state'] = NORMAL 将停用并恢复 button

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 2020-04-19
    • 2014-01-03
    • 2023-04-10
    • 1970-01-01
    • 2019-11-18
    • 2011-01-19
    相关资源
    最近更新 更多