【问题标题】:How to destroy widgets in tikinter while using functions如何在使用函数时销毁 tkinter 中的小部件
【发布时间】:2020-07-25 17:21:15
【问题描述】:

使用函数时我无法在 tkinter 中销毁小部件

def first():
    photo1 = PhotoImage(file =r"file/start.png")
    photoimage1 = photo1.subsample(5,5)
    start=Button(root,
                 width=270,
                 text="LAUNCH",
                 font=("orbitron",25),
                 image=photoimage1,
                 compound="left",
                 bg="white",
                 activebackground="white",
                 command=lambda:launch(1))
def des(var):
    start.destroy()

显示如下错误

NameError: name 'start' is not defined

谁能告诉这个错误的解决方法

【问题讨论】:

  • start 是一个局部变量。
  • 那么我怎样才能让它全球化
  • 在你的first()函数顶部说global start

标签: python user-interface tkinter error-handling


【解决方案1】:

你可以在def(first)下使用def des(var)进行销毁

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 2018-07-05
    • 2016-06-30
    • 2011-07-24
    相关资源
    最近更新 更多