Feb-25-2019, 09:47 AM
Good morning, can someone point me to literature or offer advice to help me in my current issue.
I am trying to insert the data queried from my database into a Listbox. I have been doing this successful but I am stuck on how to insert the result of the query into the Listbox easily without multiple "insert" lines as showing below.
I currently have the following working:
This way works and populates the Listbox but it does it in reverse order of the rows (last to first), in the table and it also encases the first entries (row 1 & 2), in {} brackets for some reason.
I would like to find the proper way to have the query display in proper order first - last( or if it possible in tkinter to have it query and output in alphabetical order would be nice, if that is possible), and also without the {} brackets.
Also when I query the database and currently if there is only 3 entries in the table the interpreter will show
"output0.insert(0,results[3])
IndexError: list index out of range"
because of the additional insert lines which there is no data to be pulled in the table yet.
Looking for advice on these issues.
Thanks in advance.
I am trying to insert the data queried from my database into a Listbox. I have been doing this successful but I am stuck on how to insert the result of the query into the Listbox easily without multiple "insert" lines as showing below.
I currently have the following working:
def select(): try: selection = var.get() c.execute('SELECT Recipe FROM Recipes WHERE Dish_Type = :selection', {"selection": selection}) results = c.fetchall() output0.delete(0, END) output0.insert(0,results[0]) output0.insert(0,results[1]) output0.insert(0,results[2]) output0.insert(0,results[3]) output0.insert(0,results[4]) output0.insert(0,results[5]) output0.insert(0,results[6]) output0.insert(0,results[7]) output0.insert(0,results[8]) output0.insert(0,results[9]) #================================= OptionMenu ================================== var = tkinter.StringVar(window_2) var.set('Menu') choices = [ 'Appetizers', 'Beef', 'Bread', 'Cake', 'Chicken', 'Chilli', 'Curry', 'Desert', 'Drinks', 'Egg', 'Fish', 'Pasta', 'Pork', 'Potato', 'Rice', 'Salad', 'Sandwich', 'Sauce', 'Sea Food', 'Slow Cooker', 'Soup', 'Stew', 'Tofu', 'Vegetables'] option = tkinter.OptionMenu(window_2, var, *choices) option.config(font=('Times 9 bold'), bg = "#F9F8D6", fg = "#9A0615") option.place(x=215, y=120) option["menu"].config(bg = "#F9F8D6", fg = "#9A0615") button = tkinter.Button(window_2, text="Load Category", font=('Times 9 bold'), bg = "#F9F8D6", fg = "#9A0615", command=select) button.pack button.place(x=363, y=120) #================================ OUTPUT PANE 1 ================================ output0 = tkinter.Listbox(window_2, font=('Times 9'), height = 20, width=40, bd=0, bg = "#FFD599", fg = '#9A0615') output0.pack() output0.place(x=210, y=190)Is there a wildcard value that can be used or a better way of writing the "insert" instead of using the multiple "insert(0,results [0])" lines?
This way works and populates the Listbox but it does it in reverse order of the rows (last to first), in the table and it also encases the first entries (row 1 & 2), in {} brackets for some reason.
I would like to find the proper way to have the query display in proper order first - last( or if it possible in tkinter to have it query and output in alphabetical order would be nice, if that is possible), and also without the {} brackets.
Also when I query the database and currently if there is only 3 entries in the table the interpreter will show
"output0.insert(0,results[3])
IndexError: list index out of range"
because of the additional insert lines which there is no data to be pulled in the table yet.
Looking for advice on these issues.
Thanks in advance.
"Often stumped... But never defeated."