I'm making autocomplete feature for a text editor in tkinter & python. Currently the process of autocomplete is:
If there is a input like the one in a dictionary of autocomplete,call popup
.
I do it via t_start.bind("< Key >", asprint)
where asprint
is my popup function.
I can escape the popup via escape button or by clicking elsewhere.
What I want is - upon user pressing any text key - re-trigger popup again, narrowing search in the autocomplete.
F->FI->FIL->FILE
sort of thing. I don't know what to use to get that input, AFTER the popup is open. How do I get 2nd and every following input character?
The popup function is:
def popup(event):
selected_text=''
try:
selected_text=t_start.get("sel.first", "sel.last")
except TclError:
for i in range(len(selected_text)):
if selected_text[i:0]==word[i:0]:
menu.add_command(label="%s" %selected_text, command=insert_word)
menu.delete(0)
else:
pass
menu.tk_popup(event.x_root, event.y_root)