Feb-23-2019, 06:45 AM
I am attempting to figure out how to use a variable from an MenuOption widget selection as the data in the specific column "Dish_Type" in my SQLite query.
The idea is to make a selection from the list in the MenuOption and that would be stored in the variable called "selection". During the query it should use the variable to query and print all the selected items in the column "Dish_Type" (such as Appetizers). I have not been successful in getting the query statement to successfully query and print the data for a selected category in the MenuOption yet.
Code:
The idea is to make a selection from the list in the MenuOption and that would be stored in the variable called "selection". During the query it should use the variable to query and print all the selected items in the column "Dish_Type" (such as Appetizers). I have not been successful in getting the query statement to successfully query and print the data for a selected category in the MenuOption yet.
Code:
def select(): try: selection = var.get() c.execute('SELECT * FROM Recipes WHERE Dish_Type = "+selection+" ') data = c.fetchall() print(data) except: messagebox.showerror("Error", "Data Base Error. Query failed") 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.place(x=215, y=120) button = tkinter.Button(window_2, text="Load Category", command=select) button.pack button.place(x=363, y=120I thought this "c.execute('SELECT * FROM Recipes WHERE Dish_Type = "+selection+"') would work by using the variable "selection" in the query but it is not pulling the data in the column with the name Appetizers yet. (if Appetizers was selected in the menu)
"Often stumped... But never defeated."