[英]Tkinter “Label object is not callable”
I'm trying to set the text of a Tkinter label equal to the user input from an Entry object. 我试图将Tkinter标签的文本设置为等于Entry对象的用户输入。
Here is the relevant code: 以下是相关代码:
def Return(event):
global Password
global Input
global SecurityLabel
Password = Input.get()
Parse(Password)
Variations(Password)
Search(Password)
Additions(Password)
Deductions(Password)
CheckForAdjacency(ConvertToCoordinates(Password))
MinimumRequirements(Password)
print("Your password security rating is: " + str(Security))
SecurityLabel['text'] = Security
#GUI
MainWindow = Tk()
MainWindow.title("Password Assessor")
MainWindow.geometry("500x100")
TopMenu = Menu(MainWindow)
MainWindow.config(menu = TopMenu)
subMenu = Menu(TopMenu)
TopMenu.add_cascade(label="file", menu=subMenu)
subMenu.add_command(label="boop")
Label = Label(MainWindow, text="Please enter a password:")
Label.pack(fill = 'x')
SecurityLabel = Label(MainWindow, text="")
SecurityLabel.pack(fill = 'x')
Input = Entry(MainWindow, show="*")
Input.pack(fill = 'x')
Input.focus_set
MainWindow.bind('<Return>', Return)
MainWindow.mainloop()
I grab the user's input when the return key is pressed from the entry box named Input with this code: 当我从名为Input的输入框中按下返回键并按以下代码抓取用户输入时:
Password = Input.get()
I try to set the text of a label called SecurityLabel equal to the integer "Security" with this code: 我尝试使用以下代码将名为SecurityLabel的标签的文本设置为等于整数“ Security”:
SecurityLabel['text'] = Security
The SecurityLabel is initialized with this code: SecurityLabel使用以下代码初始化:
SecurityLabel = Label(MainWindow, text="")
SecurityLabel.pack(fill = 'x')
When I try to run the code, I get this error: 当我尝试运行代码时,出现以下错误:
Traceback (most recent call last):
File "/Users/kosay.jabre/Desktop/Password Assessor/Password.py", line 242, in <module>
SecurityLabel = Label(MainWindow, text="")
TypeError: 'Label' object is not callable
I don't know what I'm doing wrong. 我不知道我在做什么错。 How can I make this work? 我该如何进行这项工作? Please try to make your explanation simple. 请尝试简化您的解释。
The problem is here: 问题在这里:
Label = Label(MainWindow, text="Please enter a password:")
Label.pack(fill = 'x')
Naming a label "Label" created some problems. 命名标签“标签”会产生一些问题。 Changing the name of this label to something other than "Label' solved the error and made the other label function properly. 将此标签的名称更改为“ Label”以外的名称可以解决该错误,并使其他标签正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.