October 13th, 2013, 11:22 AM
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, 06: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 14th, 2013, 11:51 PM
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 14th, 2013 at 11:56 PM.
October 15th, 2013, 09: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