Reputation:
I'm trying to set the text of a Tkinter label equal to the user input from an Entry object.
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:
Password = Input.get()
I try to set the text of a label called SecurityLabel equal to the integer "Security" with this code:
SecurityLabel['text'] = Security
The SecurityLabel is initialized with this code:
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.
Upvotes: 0
Views: 7527
Reputation:
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.
Upvotes: 2