如何停止选项卡在 Tkinter EntryBox 上选择文本

How to stop tab from selecting text on Tkinter EntryBox

我正在使用 AutocompleteEntry 上可用的代码为 Tkinter 附带的 Entry 小部件创建子类。

在第 57 行,handle_keyrelease() 函数似乎处理了 AutocompleteEntry 对某些按键的反应:

def handle_keyrelease(self, event):
    """event handler for the keyrelease event on this widget"""
    if event.keysym == "BackSpace":
        self.delete(self.index(Tkinter.INSERT), Tkinter.END) 
        self.position = self.index(Tkinter.END)
    if event.keysym == "Left":
        if self.position < self.index(Tkinter.END): # delete the selection
            self.delete(self.position, Tkinter.END)
        else:
            self.position = self.position-1 # delete one character
            self.delete(self.position, Tkinter.END)
    if event.keysym == "Right":
        self.position = self.index(Tkinter.END) # go to end (no selection)
    if event.keysym == "Down":
        self.autocomplete(1) # cycle to next hit
    if event.keysym == "Up":
        self.autocomplete(-1) # cycle to previous hit
    # perform normal autocomplete if event is a single key or an umlaut
    if len(event.keysym) == 1 or event.keysym in tkinter_umlauts:
        self.autocomplete()

并且右键设置为做我想做的,完成我输入的第一个单词并跳到它的末尾,我的问题如下,我想将右键更改为Tab键,但是我的输入框上的 Tab 键选择了所有文本,我找不到改变这种行为的方法,有什么办法吗?

这是我创建输入框以供参考的代码部分,对此深表歉意:

from tkinter import *
import entryautocomplete as eac

if __name__ == '__main__':
    # create Tkinter window
    master = Tk()
    # change the window name
    master.title('Jarbas')
    # avoids resizing of the window
    master.resizable(width=False, height=False)
    # center top the window on my computer
    master.geometry('+400+0')
    # adds an icon
    img = Image("photo", file="jarbas.png")
    master.tk.call('wm', 'iconphoto', master._w, img)

    # create the entry frame
    uinput = Frame(master)
    # create the other frame
    resultado = LabelFrame(
        master, text='###', labelanchor='n', font='arial 12', relief='flat')

    # places the two frames on the window
    uinput.grid()
    resultado.grid()

    # place a label on the Entry frame, picked random from a list
    Label(uinput, text=ola[randint(0, len(ola) - 1)]).grid()
    # Creates the entry
    texto = eac.AutocompleteEntry(
        uinput, font='arial 14 bold', width='60', takefocus='off')
    texto.grid(padx=5, pady=4)
    texto.set_completion_list(comandos)

    # calls the function 'get_input' once you press Return on the Entry box
    # the function reads what is typed and does what it should do
    texto.bind('<Return>', get_input)

    # tkinter main loop
    mainloop()

为了进一步参考,基于 this question,我设法通过简单地添加一个 bind 到调用 returns break 的函数的选项卡来使其工作,像这样:

def tab_handler(event):
    return 'break'

entry.bind('<Tab>', tab_handler)

并简单地将 EntryAutoComplete 文件中的 if event.keysym == "Right": 更改为 if event.keysym == "Tab":

工作得很好。