#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    How can i delete this button?


    I have this code:

    def update_count(self):
    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
    self.button1.grid()
    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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    484
    Rep Power
    33
    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.
    Code:
    try:
        import Tkinter as tk     ## Python 2.x
    except ImportError:
        import tkinter as tk     ## Python 3.x
    
    root = tk.Tk()
    
    def disable_button():
        button1['state'] = tk.DISABLED
    
    button1 = tk.Button(root, text="Upgrade", command=disable_button)
    button1.grid()
    
    root.mainloop()
    Last edited by dwblas; October 14th, 2013 at 11:56 PM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by dwblas
    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.
    Code:
    try:
        import Tkinter as tk     ## Python 2.x
    except ImportError:
        import tkinter as tk     ## Python 3.x
    
    root = tk.Tk()
    
    def disable_button():
        button1['state'] = tk.DISABLED
    
    button1 = tk.Button(root, text="Upgrade", command=disable_button)
    button1.grid()
    
    root.mainloop()
    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.

IMN logo majestic logo threadwatch logo seochat tools logo