我在 Tkinter Python 中创建了一个应用程序,该应用程序在存档中搜索多个许可证,然后将结果分组到世界列表中。找到许可证后,会出现一个按钮,如果我按下该按钮,则会在滚动文本中显示结果。我的想法是,我无法删除搜索后出现的(重新启动)按钮。有人可以帮我解决这个情况吗? 我怎样才能销毁mit_bt?
def print_to_textbox_Mit(wordlist):
if len(wordlist) >= 1:
mit_button()
def mit_button():
mit_bt = tk.Button(window, text= " M I T ", relief="groove", command=mit_print_text, activebackground="#800020").place(x=10, y=10)
def mit_print_text():
text_box.delete("1.0", tk.END)
text_box.insert("0.0", "\n !!!!!! MIT !!!!!!")
for lines in wordlist:
text_box.insert("end", "\n"+lines)
最佳答案
def print_to_textbox_Mit(wordlist):
if len(wordlist) >= 1:
mit_button()
def mit_button():
mit_bt = tk.Button(
window,
text= " M I T ",
relief="groove",
activebackground="#800020",
)
# configure your button's 'command' after declaring it above
mit_bt.configure(command=lambda b = mit_bt: mit_print_text(b))
# using a lambda here allows us to pass an argument to the 'command' callback!
mit_bt.place(x=10, y=10)
def mit_print_text(button): # pass your button as an argument to this function
text_box.delete("1.0", tk.END)
text_box.insert("0.0", "\n !!!!!! MIT !!!!!!")
for lines in wordlist:
text_box.insert("end", "\n"+lines)
# once you no longer need the button, call 'place_forget' on it to remove it
button.place_forget()
关于python - 销毁 tkinter 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74047576/