Binding a function to a key is not working

梦想与她 提交于 2019-12-02 11:46:28

When you bind a function fct to a key (or any other kind of event), the function is called with one argument like that fct(event), event having various attributes depending on the kind of event (mouse position, ...). Your problem is that the function you call drawCheckbox does not take any argument, so every time you press Enter, it raises an error

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

To correct it you can either define your function with a default argument,

def drawCheckbox(event=None):
    ...

or you can use a lambda function to do the binding

master.bind('<Return>', lambda event: drawCheckbox())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!