我对 Python(2.7)非常陌生,我正在学习 GUI 设计(Tkinter),并且在尝试通过单击按钮时从 Entry 对象实现简单的标签文本更改时不断遇到不同的语法/无调用方法/全局名称未定义错误。有人可以告诉我该操作的正确语法吗
from Tkinter import *
class Part3:
def __init__(self, parent):
GUIFrame =Frame(parent,width= 300, height=200)
GUIFrame.pack(expand = False, anchor = CENTER)
entry = Entry(text="enter your choice")
entry.place(x=65, y = 10)
self.test = StringVar()
self.test.set('''Hi, I'm a Label :)''')
self.Label1 = Label(parent, textvariable = self.test)
self.Label1.place(x = 85, y = 100)
self.Button2 = Button(parent, text='edit',command=self.LabelChange)
self.Button2.place(x= 80, y = 60)
self.Button3 = Button(parent, text='exit', command= parent.quit)
self.Button3.place(x= 160, y = 60)
def LabelChange(self):
test = self.entry.get()
self.Label1(test)
root = Tk()
MainFrame =Part3(root)
root.title('Input Test')
root.mainloop()
在“编辑”(按钮 2)上单击的想法,Label1 的文本更改为条目文本。