TypeError: login() missing 2 required positional arguments: 'username' and 'password'
You're trying to pass only one argument to a method that in actuality needs no arguments but does require 3 arguments.
When a callback, login
, is attached to a bind
method, it is sent a positional argument that represents the information about the event, usually named event
even though not explicitly passed like you did. In which case it is assumed that self
is representing the event positional argument. Though now login
lacks two positional arguments, username
and password
. Now if you actually needed those variables I'd have provided a different answer but since you don't this is the simplest I can think of.
Replace:
def login(self, username, password):
with:
def login(event):
Also, see How to pass arguments to a Button command in Tkinter? as you probably would want to use command
option of a button as opposed to a click event which won't call the method if the button is pressed with keyboard, and also bind
and command
act similarly in the sense that they both require a callback function. The only difference is that bind
implicitly passes a 1st positional argument.