a。有一个方案,我想在点击几下后删除一个按钮。 b。但是,当按钮达到最后一次点击时,它不会被破坏。 代码如下:按钮部件在试图从网格中移除时未被破坏
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()
我是否缺少任何东西?请在评论中留言!
你做了什么来调试呢?你有没有证实'self.next_button'就是你认为的? (提示:不是) –
某些缩进级别是错误的。 –