尝试从网格中删除时,按钮小工具不会被破坏

时间:2016-08-24 17:57:23

标签: python python-2.7 tkinter

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

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() 

我错过了什么吗?请注意你的意见!!

1 个答案:

答案 0 :(得分:1)

更改

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)