tkinter popup and text processing for autocomplete

前端 未结 1 1266
有刺的猬
有刺的猬 2021-01-25 09:26

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

相关标签:
1条回答
  • 2021-01-25 10:00

    The key is to keep the keyboard focus in your entry widget. When you popup your window, make sure the focus stays (or is returned to) the entry widget. Any events that affect the popup need to be attached to the entry widget rather than the popup window.

    However, if you're using a menu as your popup, this will be impossible. A menu is the wrong choice for an auto-complete feature because it steals all events until the menu is dismissed. Your popup needs to be an instance of a Toplevel widget (if you want it to "float") or some other widget (listbox, text, canvas, etc) if you want it embedded inside your window.

    There is a recipe on ActiveState that gives an example of doing autocomplete using an embedded window. http://code.activestate.com/recipes/578253-an-entry-with-autocompletion-for-the-tkinter-gui/

    0 讨论(0)
提交回复
热议问题