尝试从网格中删除时按钮小部件没有被破坏 [英] Button Widget Not Getting Destroyed While Trying To Remove From The Grid

查看:30
本文介绍了尝试从网格中删除时按钮小部件没有被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个.有一个场景,我想在点击几下后删除一个按钮.湾但是当按钮到达最后一次点击时,它不会被破坏.代码如下:

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 !!

推荐答案

更改

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

到:

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)

这篇关于尝试从网格中删除时按钮小部件没有被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆