[Solved] Disable button in Tkinter (Python)


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()

solved Disable button in Tkinter (Python)