Reputation: 17
Let's say I have a button, button = Button(root, text="Hello", command = somecommand)
and I want to disable it if some condition is true mid-program. Here is my code:
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
Thanks!
Upvotes: 0
Views: 1456
Reputation: 19144
Bookmark this reference (not perfect, but extremely helpful). The Button page says "state: Set this option to tk.DISABLED to gray out the button and make it unresponsive. Has the value tk.ACTIVE when the mouse is over it. Default is tk.NORMAL. ". In other words, button['state'] = DISABLED
and button['state'] = NORMAL
will de-activate and restore button
.
Upvotes: 3