TypeError: printName1() takes 0 positional arguments but 1 was given TypeError: printName1() takes 0 positional arguments but 1 was given tkinter tkinter

TypeError: printName1() takes 0 positional arguments but 1 was given


If you refer to the documentation regarding tkinter events and bindings, you will see that when an event is triggered, the associated event object will be passed as the first (and only) argument to the bounded function (being printName1 and friends in your case).

So what you need to do is to modify those printName* functions to accept the event argument.

def printName1(event):    print('Jack')

Then what you desired to achieve should work.

Naturally, you could make the event argument optional as @TigerhawkT3 suggested.


Events, such as from the keyboard/mouse, are all sent to the application with information about the event: which key was it, where was the mouse when you clicked, that sort of thing. This means that any callback bound to such an event needs to take an argument. If you want to also bind it to a Tkinter Button, which doesn't take an event, you can handle that as well. Just define your functions with a default argument:

def printName1(event=None):    ...