'Like search from database tkinter treeview
Hi good day to everyone I am a beginner of python programming and I have problem with searching database from my treeview. I dont know how to search "Like" method. although I can search my database but only one data and it must be accurate so It can be searched. Someone can help me with this please?
I just want to show data that has been like to others
here's my code
letter = tk.Label(t, text= "Search", font=("Bahnschrift",15))
letter.configure(font = ('Cooper', 12, 'bold'), fg = 'black')
letter.place(x=25, y=280)
s1 = tk.Entry(t, width=30, bd=3, bg = "sky blue", font = ("Bahnschrift", 10))
s1.place(x=100, y=280)
#SEARCH
def searchs():
if (s1.get()==""):
messagebox.showinfo("Error","Please Complete the Provided Details!")
else:
for record in tree.get_children():
tree.delete(record)
databases = mysql.connector.connect(
host ="localhost",
user = "userdata",
password = "",
database = "facerecog"
)
conn = databases.cursor()
conn.execute("SELECT * FROM record WHERE ids = %s ",(
s1.get(),))
i = 0
for ro in conn:
if ro[0]%2==0:
tree.insert('', i, text="",values=(ro[0], ro[1], ro[2], ro[3], ro [4], ro [5]), tags = ("even",))
else:
tree.insert('', i, text="",values=(ro[0], ro[1], ro[2], ro[3], ro [4], ro [5]),tags = ("odd",))
i = i + 1
searchbutton = tk.Button(t, text = "Search", command = searchs)
searchbutton.configure(font = ('Cooper', 13, 'bold'), bg = 'sky blue', fg = 'black')
searchbutton.place(x=135, y=320)
And here my output of Search :
Thank you in advance!
Solution 1:[1]
The solution is
databases = mysql.connector.connect(
host ="localhost",
user = "userdata",
password = "",
database = "facerecog"
)
conn = databases.cursor()
conn.execute("SELECT * FROM record WHERE names LIKE %s ",( "%" +s1.get() +"%",))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ewan_wabalo |
