Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8495235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:31:03+00:00 2026-06-10T23:31:03+00:00

Is it possible to create a combobox that updates with the closest item in

  • 0

Is it possible to create a combobox that updates with the closest item in its list as you type into it?

For example:

A = ttk.Combobox()
A['values'] = ['Chris', 'Jane', 'Ben', 'Megan']

Then you type “Chr” into the combobox, I want it to automatically fill in “Chris”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:31:04+00:00Added an answer on June 10, 2026 at 11:31 pm

    The tkinter wiki contains code for a auto-completion textbox, but since you want a combobox, you can use this code (you’re looking for AutocompleteCombobox).


    """
    tkentrycomplete.py
    
    A Tkinter widget that features autocompletion.
    
    Created by Mitja Martini on 2008-11-29.
    Updated by Russell Adams, 2011/01/24 to support Python 3 and Combobox.
    Updated by Dominic Kexel to use Tkinter and ttk instead of tkinter and tkinter.ttk
       Licensed same as original (not specified?), or public domain, whichever is less restrictive.
    """
    import sys
    import os
    import Tkinter
    import ttk
    
    __version__ = "1.1"
    
    # I may have broken the unicode...
    Tkinter_umlauts=['odiaeresis', 'adiaeresis', 'udiaeresis', 'Odiaeresis', 'Adiaeresis', 'Udiaeresis', 'ssharp']
    
    class AutocompleteEntry(Tkinter.Entry):
            """
            Subclass of Tkinter.Entry that features autocompletion.
    
            To enable autocompletion use set_completion_list(list) to define
            a list of possible strings to hit.
            To cycle through hits use down and up arrow keys.
            """
            def set_completion_list(self, completion_list):
                    self._completion_list = sorted(completion_list, key=str.lower) # Work with a sorted list
                    self._hits = []
                    self._hit_index = 0
                    self.position = 0
                    self.bind('<KeyRelease>', self.handle_keyrelease)
    
            def autocomplete(self, delta=0):
                    """autocomplete the Entry, delta may be 0/1/-1 to cycle through possible hits"""
                    if delta: # need to delete selection otherwise we would fix the current position
                            self.delete(self.position, Tkinter.END)
                    else: # set position to end so selection starts where textentry ended
                            self.position = len(self.get())
                    # collect hits
                    _hits = []
                    for element in self._completion_list:
                            if element.lower().startswith(self.get().lower()):  # Match case-insensitively
                                    _hits.append(element)
                    # if we have a new hit list, keep this in mind
                    if _hits != self._hits:
                            self._hit_index = 0
                            self._hits=_hits
                    # only allow cycling if we are in a known hit list
                    if _hits == self._hits and self._hits:
                            self._hit_index = (self._hit_index + delta) % len(self._hits)
                    # now finally perform the auto completion
                    if self._hits:
                            self.delete(0,Tkinter.END)
                            self.insert(0,self._hits[self._hit_index])
                            self.select_range(self.position,Tkinter.END)
    
            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
                    if len(event.keysym) == 1 or event.keysym in Tkinter_umlauts:
                            self.autocomplete()
    
    class AutocompleteCombobox(ttk.Combobox):
    
            def set_completion_list(self, completion_list):
                    """Use our completion list as our drop down selection menu, arrows move through menu."""
                    self._completion_list = sorted(completion_list, key=str.lower) # Work with a sorted list
                    self._hits = []
                    self._hit_index = 0
                    self.position = 0
                    self.bind('<KeyRelease>', self.handle_keyrelease)
                    self['values'] = self._completion_list  # Setup our popup menu
    
            def autocomplete(self, delta=0):
                    """autocomplete the Combobox, delta may be 0/1/-1 to cycle through possible hits"""
                    if delta: # need to delete selection otherwise we would fix the current position
                            self.delete(self.position, Tkinter.END)
                    else: # set position to end so selection starts where textentry ended
                            self.position = len(self.get())
                    # collect hits
                    _hits = []
                    for element in self._completion_list:
                            if element.lower().startswith(self.get().lower()): # Match case insensitively
                                    _hits.append(element)
                    # if we have a new hit list, keep this in mind
                    if _hits != self._hits:
                            self._hit_index = 0
                            self._hits=_hits
                    # only allow cycling if we are in a known hit list
                    if _hits == self._hits and self._hits:
                            self._hit_index = (self._hit_index + delta) % len(self._hits)
                    # now finally perform the auto completion
                    if self._hits:
                            self.delete(0,Tkinter.END)
                            self.insert(0,self._hits[self._hit_index])
                            self.select_range(self.position,Tkinter.END)
    
            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 len(event.keysym) == 1:
                            self.autocomplete()
                    # No need for up/down, we'll jump to the popup
                    # list at the position of the autocompletion
    
    def test(test_list):
            """Run a mini application to test the AutocompleteEntry Widget."""
            root = Tkinter.Tk(className=' AutocompleteEntry demo')
            entry = AutocompleteEntry(root)
            entry.set_completion_list(test_list)
            entry.pack()
            entry.focus_set()
            combo = AutocompleteCombobox(root)
            combo.set_completion_list(test_list)
            combo.pack()
            combo.focus_set()
            # I used a tiling WM with no controls, added a shortcut to quit
            root.bind('<Control-Q>', lambda event=None: root.destroy())
            root.bind('<Control-q>', lambda event=None: root.destroy())
            root.mainloop()
    
    if __name__ == '__main__':
            test_list = ('apple', 'banana', 'CranBerry', 'dogwood', 'alpha', 'Acorn', 'Anise' )
            test(test_list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create multilevel combobox using ExtJS 4.0? I mean, that it
In cocoa touch 4.x Its possible create or edit a music playlist into the
Is it possible to create a button with a drop down, or a combobox
I've seen how to bind a ComboBox to a list that has columns like
Is possible create an extension for SQL Management Studio in Visual Studio 2010? Visual
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create provisioning profile in iphone application i developed my iphone app and
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.