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

前端 未结 2 611
無奈伤痛
無奈伤痛 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:46

    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.

提交回复
热议问题