覆盖 Python Tkinter 中的默认选项卡行为

问题描述:

我正在使用 Tkinter 用 Python 编写一个应用程序来管理我的 GUI.

I am writing an application in Python using Tkinter to manage my GUI.

有一个文本输入框,我试图在其中实现一个自动完成功能,该功能将绑定到 Tab 键.

There is a text entry box on which I am trying to implement an autocompletion function which will bind to the Tab key.

我已将 Tab 键绑定到我的输入框,但是当我按下 Tab 时,程序会尝试在 GUI 元素之间循环.

I have bound the tab key to my entry box, but when I press tab, the program attempts to cycle between GUI elements.

如何覆盖此默认行为,以便 GUI 仅在按键时执行我指定的命令?

How do I override this default behavior so that the GUI will only carry out my specified command on the key press?

在事件处理程序结束时返回 'break'.它会中断事件传播.

Return 'break' at the end of your event handler. It interrupts event propagation.

def my_tab_handler(event):
    ... # handle tab event
    return 'break' # interrupts event propagation to default handlers