Am trying to query
from sqlite3
db without clicking on the button
with the command.So i did event
binding to achieve that but if i have to query
it i have to click keybaord enter key
and also i run the function query_record()
when the program starts to achieve this but not able to achieve the result.
I want the record to appear in the Listbox
as soon i enter it in the entry
widget without clicking on the button
or keyboard enter key
I know it has to be kind of event binding to achieve this but don't know how to achieve that, your suggestions are welcome to achieve this.
import tkinter as tk
import sqlite3
conn = sqlite3.connect("STATS.db")
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS institution(id INTEGER PRIMARY KEY,
name TEXT)")
conn.commit()
conn.close()
root = tk.Tk()
root.geometry("300x300")
List = tk.Listbox(root, width=100)
List.pack()
e1_search = tk.StringVar()
e1 = tk.Entry(root, textvariable=e1_search)
e1.pack()
def query_record(event=None):
data1 = e1_search.get()
conn = sqlite3.connect("STATS.db")
cur = conn.cursor()
cur.execute("SELECT * FROM institution WHERE name like ?", (data1+"%",))
row = cur.fetchall()
for n in row:
List.delete(0, tk.END)
List.insert(tk.END, n)
print(n)
conn.close()
query_record()
e1.bind("<Return>", query_record)
b = tk.Button(text="Search", command=query_record)
b.pack(side=tk.BOTTOM)
root.mainloop()