我想知道是否有人能指出我在正确的方向,请下面是一个小例子,按我的应用程序。一旦按下,应用程序就会将文本显示在Tkinter标签上。我的问题是,当按下按钮时,GUI会被标签的多行填充。无论点击多少次按钮,如何才能使标签只出现一次。
谢谢
import tkinter as tk
def testapp():
w = tk.Label(root, text="Hello again!")
w.pack()
root = tk.Tk()
w = tk.Button(root, text="Press Me!",command=testapp)
w.pack()
root.mainloop()
发布于 2022-05-05 11:48:19
import tkinter as tk
global_label = None
def testapp():
global global_label
if not global_label:
global_label = tk.Label(root, text="Hello again!")
global_label.pack()
root = tk.Tk()
w = tk.Button(root, text="Press Me!", command=testapp)
w.pack()
root.mainloop()
https://stackoverflow.com/questions/72132654
复制相似问题