I don't know what I'm doing wrong when I'm trying to insert some values from my database to my entries. I have a main interface with the same code working well, but I've created a secondary window and tried to make work almost the same code but it's not working. It gives me this error:
sqlite3.OperationalError: incomplete input
This is my code:
myid = StringVar()
myname = StringVar()
myowner = StringVar()
mycel = StringVar()
id_entry = Entry(windows2, textvariable=myid)
name_entry = Entry(windows2, textvariable=myname)
owner_id = Entry(windows2, textvariable=myowner)
cel_id = Entry(windows2, textvariable=mycel)
btn_search = Button(windows2, text='SEARCH', command=lambda: search())
btn_search.place(x=930, y=12, width='60', height='26')
def search():
conn = sqlite3.connect('db1.db')
c = conn.cursor()
c.execute("SELECT * FROM regis WHERE idcard=" + myid.get())
theuser = c.fetchall()
for user in theuser:
myid.set(user[0])
myname.set(user[1])
myowner.set(user[8])
mycel.set(user[9])
conn.commit()
if theuser:
messagebox.showinfo(title='ID Found', message='User found')
else:
messagebox.showerror(tittle=None, message='Wrong ID')
myid.get()before executing the SQL statement to see whether it has the value you expected.Tk()as your second window. UseToplevel()instead.c.execute("SELECT * FROM regis WHERE idcard=?", [myid.get()])in order to avoid SQL injection.