I'm new to programming, learnt python syntax. Stuck at my first GUI program!
Here is my code:
#User name
userLabel = Label(self.signView, text="User Name")
userLabel.grid(sticky = E)
self.userEntry = Entry(self.signView)
self.userEntry.grid(row=0, column=1)
self.labelUserVar = StringVar()
self.validLabel = Label(self.signView, textvariable=self.labelUserVar,
anchor="w", fg="red")
self.validLabel.grid(row=0, column=2)
self.userEntry.bind("<Return>", self.CheckUser)
Here's the following CheckUser() function:
def CheckUser(self):
self.labelUserVar.set("unavailable user name!")
I got this error.
TypeError: CheckUser() takes exactly 1 argument (2 given)
The function you pass to .bind()
takes the event as an argument, and it will be passed in regardless of whether you need it.
Change the function definition to
def CheckUser(self, event):
self.labelUserVar.set("unavailable user name!")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With