Bind or Command to get return and button to work

旧时模样 提交于 2019-12-02 07:07:24

The normal way to share a function between a button and a binding is to make the event parameter optional, and to not depend on it. You can do that like this:

def search(event=None):
    ...

bttn = Button(..., command=search)
...
entr.bind('<Return>', search)

If you omit the command and rely on a bound event, you lose the built-in keyboard accessibility that Tkinter offers (you can tab to the button and press the space bar to click it).

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