我在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()
答案 0 :(得分:0)
为了进一步参考,基于this question,我设法通过简单地向bind
调用return
s break
函数的标签添加def tab_handler(event):
return 'break'
entry.bind('<Tab>', tab_handler)
来实现它。 :
if event.keysym == "Right":
并简单地将EntryAutoComplete文件中的if event.keysym == "Tab":
更改为readelf
工作得很好。