Dec-10-2024, 03:34 PM
Hi!
I'm trying to link two comboboxes but I'm running into the retrieval of the second one after selection.
---------------------- -------------------
| Table1 | | Table2 |
--------------------- -------------------
| table1Id | | table2Id |
|-------------------- |-----------------
| table1Name | | table2Name |
|-------------------- | ----------------
| table1Contact | | table1Id |
I would like that by selecting a value in list one, the elements linked to it are displayed in the second list and here's how I did it:
"""
Here's how i feed the 1st combobox
"""
def listProv():
qSallProv = 'SELECT DISTINCT provNom FROM prov;'
conn.execute(qSallProv)
provQR = conn.fetchall()
listProv = [prov[0] for prov in provQR]
return listProv
"""
Here's how i feed the 2nd combobox
"""
vNaissList = []
def listVille():
qSallVilleProv = "SELECT DISTINCT villeNom, provNom FROM ville AS v JOIN prov AS p ON p.provId = v.villeCodeProv WHERE provNom = '"+sel.get()+"';"
conn.execute(qSallVilleProv)
villeProvQR = conn.fetchall()
vNaissList = [ville[0] for ville in villeProvQR]
return vNaissList
"""
Getting the 1st combobox selected value
"""
sel = tk.StringVar()
"""
List of 1st combobox
"""
provNaissList = ttk.Combobox(labelInfoCiv, values=listProv(), textvariable=sel)
provNaissList.grid(row=3,column=0, sticky='ew')
"""
List of 2nd combobox
"""
villeNaissList = ttk.Combobox(labelInfoCiv, values=listVille())
villeNaissList.grid(row=4,column=0, sticky='ew')
sel.trace('w',villeNaissList)
The first list is ok and all i want appears but the second still be blank.
I don't know where i'm wrong.
I'm trying to link two comboboxes but I'm running into the retrieval of the second one after selection.
---------------------- -------------------
| Table1 | | Table2 |
--------------------- -------------------
| table1Id | | table2Id |
|-------------------- |-----------------
| table1Name | | table2Name |
|-------------------- | ----------------
| table1Contact | | table1Id |
I would like that by selecting a value in list one, the elements linked to it are displayed in the second list and here's how I did it:
"""
Here's how i feed the 1st combobox
"""
def listProv():
qSallProv = 'SELECT DISTINCT provNom FROM prov;'
conn.execute(qSallProv)
provQR = conn.fetchall()
listProv = [prov[0] for prov in provQR]
return listProv
"""
Here's how i feed the 2nd combobox
"""
vNaissList = []
def listVille():
qSallVilleProv = "SELECT DISTINCT villeNom, provNom FROM ville AS v JOIN prov AS p ON p.provId = v.villeCodeProv WHERE provNom = '"+sel.get()+"';"
conn.execute(qSallVilleProv)
villeProvQR = conn.fetchall()
vNaissList = [ville[0] for ville in villeProvQR]
return vNaissList
"""
Getting the 1st combobox selected value
"""
sel = tk.StringVar()
"""
List of 1st combobox
"""
provNaissList = ttk.Combobox(labelInfoCiv, values=listProv(), textvariable=sel)
provNaissList.grid(row=3,column=0, sticky='ew')
"""
List of 2nd combobox
"""
villeNaissList = ttk.Combobox(labelInfoCiv, values=listVille())
villeNaissList.grid(row=4,column=0, sticky='ew')
sel.trace('w',villeNaissList)
The first list is ok and all i want appears but the second still be blank.
I don't know where i'm wrong.