-1
目前正在使用GUI Python。我创建了一个按钮,可以更改标签所说的内容,但是,我无法将lbtext
的新值“导出”回全局名称空间。我怎么做?这里是我的代码:Python Tkinter按钮的回调不会更改全局变量
from tkinter import *
lbtext = ""
def llb():
global lbtext
lbtext = "Hi"
master = Tk()
top = Canvas(master, name="gui")
but = Button(top, text="This is a button", command=llb)
but1 = Button(top, text='Meaning of life is: ', command=llb)
lb = Label(top, text=lbtext)
objs = [top, but, but1, lb]
for i in objs:
i.pack()
mainloop()
谢谢!
你是什么意思是“将'lbtext的新值导回到全局名称空间中”? –
所以程序的其余部分可以使用新值。我不知道它的正确名词。 – mehmenmike