Vimo
Vimo

Reputation: 1143

Button Widget Not Getting Destroyed While Trying To Remove From The Grid

a. Have a scenario where I wanted to remove a button after few clicks. b. But when the button reaches the last click, its not getting destroyed. Code as given below:

from tkinter import *

class test_button:
    def __init__(self, master):
        self.master = master
        self.next_button = None

        if not (self.next_button): 
            self.next_button = Button(root, background="orange red", activebackground="orangered3", text="Next Test Config", command=self.next_button_code).grid(row=1, column=1)

    def next_button_code(self):
        if self.next_button:
            self.next_button.destroy(); self.next_button = None

# Top Local Variables
root = Tk()

# Top Level Default Codes
my_gui = test_button(root)

root.mainloop() 

Am I missing anything ? Kindly drop in your comments !!

Upvotes: 0

Views: 128

Answers (1)

Parviz Karimli
Parviz Karimli

Reputation: 1287

Change

self.next_button = Button(root, background="orange red", activebackground="orangered3", text="Next Test Config", command=self.next_button_code).grid(row=1, column=1)

to:

self.next_button = Button(root, background="orange red", activebackground="orangered3", text="Next Test Config", command=self.next_button_code)
self.next_button.grid(row=1, column=1)

Upvotes: 1

Related Questions