Python Forum
[Tkinter] interlinked Comboboxes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] interlinked Comboboxes
#1
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.
buran write Dec-10-2024, 03:52 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply


Messages In This Thread
interlinked Comboboxes - by azelor - Dec-10-2024, 03:34 PM
RE: interlinked Comboboxes - by menator01 - Dec-10-2024, 04:57 PM
RE: interlinked Comboboxes - by azelor - Dec-10-2024, 05:34 PM
RE: interlinked Comboboxes - by deanhystad - Dec-10-2024, 06:07 PM
RE: interlinked Comboboxes - by menator01 - Dec-11-2024, 07:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter database aware cascading comboboxes to update properly dford 6 5,798 Jan-11-2022, 08:37 PM
Last Post: deanhystad
  Linking Comboboxes MrP 24 11,018 Feb-03-2021, 10:59 PM
Last Post: MrP
  Print Values from a Sequence of Entries / ComboBoxes MC2020 4 4,694 Mar-28-2020, 10:05 PM
Last Post: MC2020
  [PyQt] making dependant comboBoxes Hitsugaya 3 6,251 May-23-2019, 06:05 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020