Disable Button In Tkinter (python)
Hi , I have some question to ask I just want to disable the button when i start my program in attached image, it looks like the button is already disabled ,but its response to my
Solution 1:
You need to unbind
the event. state="disabled"
/state=DISABLED
makes button disabled
but it doesn't unbind
the event. You need to unbind
the corresponding events
to achieve this goal. If you want to enable the button again then you need to bind
the event again. Like:
from Tkinter import *
def printSomething(event):
print("Print")
#Start GUI
gui = Tk()
gui.geometry("800x500")
gui.title("Button Test")
mButton = Button(text="[a] Print",fg="#000",state="disabled")
mButton.place(x=5,y=10)
mButton.bind('<Button-1>',printSomething)
mButton.unbind("<Button-1>") #new line added
gui.bind('a',printSomething)
gui.mainloop()
Post a Comment for "Disable Button In Tkinter (python)"