I am new to python and I am trying to make a budget tracking application, with GUI. To do this I enter every amount I spend in the programme. These amounts are stocked in an sqlite DB, where every amount has a general category and every category has multiple subcategories. This will make it possible to generate statistics, based on the category and subcategory linked to every amount entered.
All the possible categories and subcategories that I can select are stored in an sqlite DB and these are can be selected in the GUI via comboboxes. My objective is that when I select a certain category in the category combobox, only the subcategories linked to this category are displayed in the subcategory combobox.
The problem I am encountering is that I cannot reference the value selected in the category combobox to filter the values that will be visible in the subcategory combobox.
The part of my code that causes problems is the following:
query = c.execute('SELECT Name_Subcategory FROM Subcategory WHERE ID_Category == Categorybox.get()')
When I change "Categorybox.get()" by an ID_Category which can be found in my sqlite DB (for example 2) the code works and the possible subcategories in the subcategory comboboxes are filtered to only show those subcategories with ID_Category value "2".
Does anyone know a way to resolve this issue? Thanks in advance for any advice you can give.
Overview Gui and DB tables
#connect database
conn = sqlite3.connect("Budget.db")
#create cursor
c = conn.cursor()
# Combobox_Category
def Cat_opt():
conn = sqlite3.connect('Budget.db')
query = c.execute('SELECT Name_Category FROM Category')
data = []
for row in c.fetchall():
data.append(row[0])
return data
conn.close(row=1, column=0)
Category_box = Combobox(width=27)
Category_box['value'] = Cat_opt()
# Combobox_Subcategory
def Subcat_opt():
conn = sqlite3.connect('Budget.db')
query = c.execute('SELECT Name_Subcategory FROM Subcategory WHERE ID_Category == Categorybox.get()')
data = []
for row in c.fetchall():
data.append(row[0])
return data
conn.close(row=1, column=0)
Subcategory_box = Combobox(width=27)
Subcategory_box['value'] = Subcat_opt()
