Bind or Command to get return and button to work

前端 未结 1 1197
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 19:08

I have a simple question about the bind() method and the command argument. Usually, in a program, you can click on a button related to what you are doi

相关标签:
1条回答
  • 2021-01-24 20:04

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

    0 讨论(0)
提交回复
热议问题