Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: takes exactly 1 argument (2 given)

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)
like image 895
Gabriel Avatar asked Jan 09 '23 17:01

Gabriel


1 Answers

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!")
like image 94
Sven Marnach Avatar answered Jan 21 '23 21:01

Sven Marnach