一个。有一个场景,我想在几次点击后删除按钮。 湾但是当按钮到达最后一次点击时,它不会被破坏。 代码如下:
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()
我错过了什么吗?请注意你的意见!!
答案 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)