Updating a Tkinter Widget:
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 becomedisabled; 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
mattyd
Posting Maven
2,607 posts since Oct 2006
Reputation Points: 105
Solved Threads: 1
What do you do to re-enable the button?
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
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
mattyd
Posting Maven
2,607 posts since Oct 2006
Reputation Points: 105
Solved Threads: 1
You could simply add something like line
btn1.configure(state=DISABLED)
into your show_image2 function.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
What do you do to re-enable the button?
Use something like b.configure(text="Enabled", state=NORMAL)
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417