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

前端 未结 2 614
無奈伤痛
無奈伤痛 2020-12-11 23:21

So I have this very simple thing I wrote and it\'s killing me trying to figure out why it won\'t work. All it does it print a statement when you click.

So for the f

2条回答
  •  臣服心动
    2020-12-11 23:50

    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):
        ...
    

提交回复
热议问题