0
我在AutocompleteEntry上使用此代碼可用於爲Tkinter附帶的Entry小部件創建子類。如何停止在Tkinter EntryBox上選擇文本的選項卡
在第57行中,handle_keyrelease()函數似乎處理TE 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()