我使用Tkinter,有一个条目和一个“搜索”按钮。如果我们在条目中输入一个文本并点击搜索按钮,效果会很好。它调用了一个名为search\u country的函数。 但是,如果我们点击搜索按钮或只按回车键,我想呼叫搜索国家。然后我绑定这个:entry.bind(“”,search\u country),它显示了这个错误
entry = Entry(win)
entry.grid(row=0, column=1)
entry.bind('<Return>', search_country)
button_search = Button(f2, text="Search", command= search_country)
button_search.grid(row=0, column=2)
def search_country():
search_ = " ".join(entry.get().split()).title().replace('And','&')
entry.delete(0,"end")
if search_ in countries:
country_index= countries.index(search_)
listbox.selection_clear(0, END)
listbox.select_set(country_index)
showimg(country_index)
我尝试了很多方法,但我只得到了两种方法中的一种:点击搜索按钮或在条目中按enter键。我需要两种方法正确工作
多谢各位
当你这样做的时候
绑定函数获取
event
作为参数因此,您可能需要在绑定函数中添加此参数
一些文件https://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
相关问题 更多 >
编程相关推荐