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

  • Home
  • SEARCH
  • 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 3985336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:52:42+00:00 2026-05-20T05:52:42+00:00

I’m trying to build a search engine that will check a list and then

  • 0

I’m trying to build a search engine that will check a list and then remove all list items that do not meet the search parameters. I know there is several problems with my program such as it will not add things back to the list when you backspace and in my updating for loop I simply tack on a ‘*’ thinking that it will search for strings only beginning with the current parameters, but I will cross those bridges later.

class StudentFinderWindow(Tkinter.Toplevel):

def __init__(self):
    Tkinter.Toplevel.__init__(self) # Create Window

    searchResultList = ['student1', 'student2', 'student3'] # Test list.

    ##### window attributes
    self.title('Edit Students') #sets window title.

    ##### Puts stuff into the window.

    # text
    editStudentInfoLabel = Tkinter.Label(self,text='Select the student from the list below or search for one in the search box provided')
    editStudentInfoLabel.grid(row=0, column=0)

    # Entry box
    self.searchRepositoryEntry = Tkinter.Entry(self)
    self.searchRepositoryEntry.grid(row=1, column=0)

    # List box
    self.searchResults = Tkinter.Listbox(self)
    self.searchResults.grid(row=2, column=0)

This fills the Tkinter Listbox with the original list.

    # Search results initial updater.
    self.getStudentList()
    for student in self.studentList:
        self.searchResults.insert(Tkinter.END, student)

    ##### Event handler

Right here I bind to run the list updater after a key is entered into the search box

    self.searchRepositoryEntry.bind('<Key>', self.updateSearch)

This is supposed to run every time a key is pressed. It gets the string that is in the Entry then starts a variable count so I know which index the name is at. After that it run a for loop on the current list supposedly checking to see if it fits the requirement of the parameters and any other letter after it. If it does not match it should delete. The problem is the first time I hit a letter the parameters string is just a blank space and then the next letter the string is the first letter and so on. It is always one step behind. And that is the problem

def updateSearch(self, event):
    parameters = self.searchRepositoryEntry.get()
    int = 0
    currentList = self.searchResults.get(0, Tkinter.END)
    for i in currentList:
        if not i == parameters + '*':
            self.searchResults.delete(int)
        int += 1

def getStudentList(self):
    global fileDirectory # Gets the directory that all the files are in.
    fileList = listdir(fileDirectory)
    self.studentList = []
    for file in fileList:
        self.studentList.append(file[:-4])
  • 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-20T05:52:43+00:00Added an answer on May 20, 2026 at 5:52 am

    I believe I have run into this same problem you describe before, when attempting to make an actively searching ctrl-F feature in one of my programs.

    What I found to work is not bind on Key but instead KeyRelease. I’m not entirely sure why this works (probably just a quirk with Tkinter). However, it works.

    Snippet’s:

    The binding

    # self.FW.En is an entry widget.
    self.FW.En.bind('<KeyRelease>', self.find)
    

    Which would run

    def find (self, event):
    
            self.Te.tag_remove('found', '1.0', 'end')
            pat = self.FW.En.get()
            if len(pat) > 1:
                index = '1.0'
                while True:
                    index = self.Te.search(pat, index, nocase=1, stopindex='end')
                    if not index:
                        break
                    lastidex = '%s+%dc' % (index, len(pat))
                    self.Te.tag_add('found', index, lastidex)
                    index = lastidex
    
                self.Te.tag_config('found', background='#80ff00')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.