python - 销毁 tkinter 按钮

标签 python tkinter

我在 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/

相关文章:

python - 如何在 python 中对命令行参数进行分组?

python - 根据 OptionMenu 的选择运行命令

Python Tkinter 通过函数更新文本框内容

python - 尝试使用按钮打破 python 2.7 tkinter 中的 while 循环串行 readline () 函数。从 aruduino Mega 读取数据

python - 从 scrapy 爬虫获取空结果

python - Odoo v9 - 在编辑表单(不创建)时设置动态域

python - 使用 re.match 提取 url 模式中的部分

python - 从 Tkinter 的 Entry 中获取值(value)

python - 如何让滚动条看起来更好

python - 计算训练集的混淆矩阵