Feb-22-2020, 05:49 PM
I am in a bit of a stumped situation. I have a small program that I am writing and so far so good however I am having a little difficulty with a binding and a SQLite database query.
The basics of the program is a window contains a few widgets and the first widget is populated with different words. The user will click on 1 of the words and it should query the database and then insert only the result in to a second widget.
I have it binding and going to the query however it is not pulling the data correctly because I am having difficulty finding the correct way to define a variable for the words in the widget so it can pull only the correct data from the correct column in the DB.
How can I use or assign a variable to be used with the binding and query so I can click on any word and it query the DB for only that information?
Here is the binding:
The basics of the program is a window contains a few widgets and the first widget is populated with different words. The user will click on 1 of the words and it should query the database and then insert only the result in to a second widget.
I have it binding and going to the query however it is not pulling the data correctly because I am having difficulty finding the correct way to define a variable for the words in the widget so it can pull only the correct data from the correct column in the DB.
How can I use or assign a variable to be used with the binding and query so I can click on any word and it query the DB for only that information?
Here is the binding:
category_label = Label(root, text='Categories', font = ('arial', 8, 'bold'), bd = 2, width = '20', fg = '#FFFFFF', bg='#284287', relief = RAISED)
category_label.place(x=975,y=33)
category = Listbox(root, font = ('arial', 8, 'bold'), bg='#FFFFDF', fg='#000000', bd=3, width=45, height=13, highlightthickness=0, relief=SUNKEN)
category.place(x=975,y=55)
category.bind('<ButtonRelease-1>', getSnippet)Here is the def statement for the query:def getSnippet(event):
try:
selection = var.get()
c.execute('SELECT List FROM Categories WHERE List = :selection ORDER BY Code DESC',
{'selection': selection})
results = c.fetchall()
for result, in results:
snippet_list.insert(1.0, result)
except:
messagebox.showerror('PBSnippet', 'Failed to load category')Much appreciated as always.
"Often stumped... But never defeated."
