I need to change the state of a Button from DISABLED to NORMAL when some event occurs.
The button is currently created in the DISABLED state using the following code:
self.x = Button(self.dialog, text="Download", state=DISABLED, command=self.download).pack(side=LEFT) How can I change the state to NORMAL?
First, import the Tkinter package. Now we'll create an app object and set the window size to 200 x 200. We'll add two more buttons, button 1 and button 2. We'll offer an argument as an app that will be displayed in the app window, and we'll give it a name by setting text attributes to “Python Button 1.”
Tkinter Button has two states, NORMAL - The button could be clicked by the user. DISABLE - The button is not clickable.
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With