My current GUI program, in part, will display a button which the user may choose to press (or not, in some cases):

btn1 = Button(root ,bg="Black", text="HIT", image=image01,command=show_image2)
btn1.configure(state=NORMAL,background='red' )
btn1.pack()

This is basic and works fine.

The issue I am having is that after the button is chosen and pressed I would like this button to become disabled; this would require an update of sorts. Logically, as far as I can tell, this would be to use update_idletasks(). I have used this in other areas of the code with animation (the display of GIFs, etc) and it works most excellent. I have tried it along with the above code but it does not disable the button as I wish it to:

btn1.update_idletasks()
btn1 = Button(root ,bg="Black", text="HIT",   image=image01,command=show_image2)
btn1.configure(state=DISABLE,background='red' )
btn1.pack()

The syntax is incorrect and\or I am missing something that should be in there. I have the suspicion that there is more to updating a widget (a button) than there is a GIF but no research or documentation has shown this.

Thank-you for all help in advance.

sharky_machine

Hi!

I don't have to update anything when I disable a button:

from Tkinter import *

def disable_it():
    b.configure(text="Disabled", state=DISABLED)

root = Tk()

b = Button(text="Enabled", command=disable_it)
b.pack()

root.mainloop()

I haven't tested it with gif's, maybe there is a difference.

Regards, mawe

Comments
Good advice (Tkinter button disabling)

Hi!

I don't have to update anything when I disable a button:

from Tkinter import *
 
def disable_it():
    b.configure(text="Disabled", state=DISABLED)
 
root = Tk()
 
b = Button(text="Enabled", command=disable_it)
b.pack()
 
root.mainloop()

I haven't tested it with gif's, maybe there is a difference.

Regards, mawe

Thank-you for your reply. This is a nice, tidy solution. The problem is: command=disable_it. I already have a command loaded into my button code for this particular button (when the user chooses and presses this button a card image is displayed in the GUI). I cannot with Python\ Tkinter, unfortunately, have more than one (1) command in the code. I need to figure out another way to make this same thing happen minus "command". I like your submitted example and I am going to save it in my code snippet library as it seems a nice way to deal with button display issues in the future. I learned something useful today. Thank-you.

Regards,
sharky_machine

from Tkinter import *

def disable_it():
    b.configure(text="Disabled", state=DISABLED)
    do_something_else()

def do_something_else():
    print "something_else"

def enable_it():
    b.configure(text="Enabled", state=NORMAL)

root = Tk()

b = Button(text="Enabled", command=disable_it)
b.pack()
Button(text="ReEnable", command=enable_it).pack()

root.mainloop()
This question has already been answered. Start a new discussion instead.