October 13th, 2013, 12:22 PM
How can i delete this button?
I have this code:
self.button_clicks += 1
self.button["text"] = "Total Clicks: " +str(self.button_clicks)
if self.button_clicks == 5:
self.button1 = Button(self)
self.button1["text"] = "Upgrade"
self.button1["command"] = self.upgrade_cor
if self.button_clicks < 5:
self.button1['state'] = DISABLED
why cant i disable the button?(its part from a longer code so it might be confusing but im sure someone can see the problem here.
October 13th, 2013, 07:36 PM
Check the scope, if it's not being disabled it's because the button mode
is not being set.
It looks to be immutable, so there may be a bogus memory address.
try setting the button to a global scope.
I'm not sure. But It looks like a bad reference caused by a scoping bug.
October 15th, 2013, 12:51 AM
The code you posted creates the button if clicks==5, but disables the (not yet created) button for clicks < 5. The following code works as (at least as I) expected.
import Tkinter as tk ## Python 2.x
import tkinter as tk ## Python 3.x
root = tk.Tk()
button1['state'] = tk.DISABLED
button1 = tk.Button(root, text="Upgrade", command=disable_button)
Last edited by dwblas; October 15th, 2013 at 12:56 AM.
October 15th, 2013, 10:13 AM
i already fix it it was just a simple problem, i did not set the button to "NORMAL" when i created the button, when i did it solved the problem.
Originally Posted by dwblas