Python Forum
problem python search engine - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: problem python search engine (/thread-29681.html)



problem python search engine - forumpy - Sep-15-2020

hi,i need help, I want to create a python search engine that will search for clients' names (from a sqlite3 database and display them on the Treeview object),search automatically without clicking on search Button (i.e. in real time).
The code below allows a good search but the problem is that it doesn't take into account the last letter typed.
example
if I write in the search field 'Nam' it executes the search for 'Na' just
if I write in the search field 'Name' it performs the search for 'Nam' just (i.e. either press enter or a key so that it performs the search)
def SearchByName(event):
    for x in Tree.get_children():
        Tree.delete(x)
    Name = entrySearchByName.get()
    conn = sqlite3.connect('database.db')
    cur = conn.cursor()
    SQL = "SELECT*FROM customers where Name LIKE ?"
    Wc_Name = "%{}%".format(Name)
    select = cur.execute(SQL, (Wc_Name,))
    select =list(select)
    conn.commit()
    for row in select:
        Tree.insert('', END, values = row)
        conn.close()

lbSearchByName = Label(root, text="Search By Name :", font=("Times New Roman",18))
lbSearchByName.place(x=540, y=2)
entrySearchByName = Entry(root)
entrySearchByName.place(x=730, y=7, width=250, height=25)
entrySearchByName.bind("<Key>", SearchByName)