How to change Tkinter Button state from disabled to normal?

scandalous picture scandalous · Apr 16, 2013 · Viewed 134.9k times · Source

I need to change the state from DISABLED to NORMAL of a Button when some event occurs.

Here is the current state of my Button, which is currently disabled:

  self.x = Button(self.dialog, text="Download",
                state=DISABLED, command=self.download).pack(side=LEFT)

 self.x(state=NORMAL)  # this does not seem to work

Can anyonne help me on how to do that?

Answer

Sheng picture Sheng · Apr 16, 2013

You simply have to set the state of the your button self.x to normal:

self.x['state'] = 'normal'

or

self.x.config(state="normal")

This code would go in the callback for the event that will cause the Button to be enabled.


Also, the right code should be:

self.x = Button(self.dialog, text="Download", state=DISABLED, command=self.download)
self.x.pack(side=LEFT)

The method pack in Button(...).pack() returns None, and you are assigning it to self.x. You actually want to assign the return value of Button(...) to self.x, and then, in the following line, use self.x.pack().