我无法使用键绑定来更改标签或任何参数的值.
这是我的代码:
from tkinter import*
class MyGUI:
def __init__(self):
self.__mainWindow = Tk()
#self.fram1 = Frame(self.__mainWindow)
self.labelText = 'Enter amount to deposit'
self.depositLabel = Label(self.__mainWindow, text = self.labelText)
self.depositEntry = Entry(self.__mainWindow, width = 10)
self.depositEntry.bind('', self.depositCallBack)
self.depositLabel.pack()
self.depositEntry.pack()
mainloop()
def depositCallBack(self,event):
self.labelText = 'change the value'
print(self.labelText)
myGUI = MyGUI()
当我运行这个,我单击输入框,然后按回车键,希望标签将值更改为“更改值”.但是,当打印该文本时,标签保持不变.
从对类似问题和问题的其他问题的看法,我已经想到了如何在课外进行一些工作,但是我在课堂上做了一些困难.
另外,在旁注中,“主人”在tkinter中扮演什么角色?