【问题标题】:How to delete and redisplay a tkinter label如何删除和重新显示 tkinter 标签
【发布时间】:2020-12-05 02:12:10
【问题描述】:

我有一个 Dropbox,我想打印一个可以工作的选定水果选项,但我希望它删除以前显示的水果并将新选择的水果放在它的位置,但它只在第一个下面显示新水果

这是程序

   fruits=["apple",
        "mango",
        "pear",
        "orange"]
clicked=StringVar()
clicked.set(fruits[0])

drop=OptionMenu(root,clicked,*fruits)
drop.pack()

def Print():         
display=Label(root,text=clicked.get()).pack()

button=Button (root,text="Print",command=Print)

【问题讨论】:

标签: python-3.x tkinter label


【解决方案1】:

当然会这样做,您每次通过调用 tk.Label() 创建一个新的 Label 类实例。最简单的解决方案是将变量作为文本变量添加到标签中。

Display = Label(root, textvariable=clicked)

https://stackoverflow.com/a/2603371

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多