简体   繁体   中英

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)

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!")

This:

server.bind((host,port))

Not this:

server.bind(host,port)

Bind the address (host, port) to the socket. Under AF_.NET, the address is expressed in the form of a tuple (host, port).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM