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 7087739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:42:39+00:00 2026-05-28T07:42:39+00:00

I found a fun autocomplete widget class on the internet–which I’ve stripped down to

  • 0

I found a fun autocomplete widget class on the internet–which I’ve stripped down to the essentials–to make my boring python 2.7 tkinter entry windows autocomplete entry windows.

from Tkinter import*

class AutocompleteEntry(Entry):

    def set_completion_list(self, completion_list):
        self._completion_list = completion_list
        self._hits = []
        self._hit_index = 0
        self.position = 0
        self.bind('<KeyRelease>', self.handle_keyrelease)               

    def autocomplete(self, delta=0):
        if delta:
            self.delete(self.position,END)
        else:
            self.position = len(self.get())
        _hits = []
        for element in self._completion_list:
            if element.startswith(self.get().lower()):
                _hits.append(element)
                if _hits != self._hits:
                        self._hit_index = 0
                        self._hits=_hits
        if _hits == self._hits and self._hits:
                self._hit_index = (self._hit_index + delta) % len(self._hits)
        if self._hits:
                self.delete(0,END)
                self.insert(0,self._hits[self._hit_index])
                self.select_range(self.position,END)

    def handle_keyrelease(self, event):
        if len(event.keysym)== 1:
            self.autocomplete()

class Code:
    def __init__(self, parent):
        self.myParent = parent
        self.main_frame = Frame(parent, background="light blue")
        self.main_frame.pack(expand=YES, fill=BOTH)

        test_list = ('test', 'type', 'true', 'tree')

        self.enter = AutocompleteEntry(self.main_frame, width=30)
        self.enter.set_completion_list(test_list)
        self.enter.pack(side=LEFT, expand=NO)



root = Tk()
code = Code(root)
root.mainloop() 

Works great, with one annoying caveat: seems the list which the autocomplete references is bias towards lowercase words. This snippet works:

test_list = ('test', 'type', 'true', 'tree')

Change the list to uppercase and the autocomplete function vanishes.

test_list = ('Test', 'Type', 'True', 'Tree')

I’ve gone back to the original internet code http://tkinter.unpythonic.net/wiki/AutocompleteEntry and it shows the same flaw. How do I alter the autocomplete widget code to eliminate this bias, allowing it to accept lists with upper and lowercase words?

  • 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-05-28T07:42:40+00:00Added an answer on May 28, 2026 at 7:42 am

    Try removing the

    .lower()

    from

    if element.startswith(self.get().lower()):
    

    or to make the match case-insensitive:

    if element.lower().startswith(self.get().lower()):
    

    which will convert your entry string into lowercase and then the list values to lowercase as well so that a match will be made anytime the same letters are entered even if the case is off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found myself designing a language for fun that is a cross between
I'm trying to make a simple msn client mostly for fun but also for
Currently, I am using a type-safe enum class from Boost Vault : Which Typesafe
I've been working on some jQuery widget for work/fun lately ( github ) and
I've found a few related questions, like Python vs. Perl (now deleted) and Is
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
Found the following in an Oracle-based application that we're migrating (generalized) : SELECT Table1.Category1,
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:

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.