I'm working on a tkinter project that has 2 comboboxes, sourced with a dictionary.
The first one have to receive the key of the dictionary as choices.
The second one will receive the values of the selected key as choices.
Here is the code:
from tkinter import *
from tkinter import ttk as ttk
import resources #dictionary file
root=Tk()
root.geometry("600x600")
label=Label(root, text="cbb1")
label.grid(row=1, column=1)
key=[i for i in resources.Dico.keys()]
cbb = ttk.Combobox(root, values=key)
cbb.grid(row=1, column=2)
def callback(event):
selected_key=cbb.get()
return selected_key
cbb.bind('<<<ComboboxSelected>>>', callback)
label2=Label(root, text="Cbb2")
label2.grid(row=2, column=1)
cbb2=ttk.Combobox(root, values=[i for i in resources.Dico[selected_key]])
cbb2.grid(row=2, column=2)
root.mainloop()
Source example:
Dico={}
Dico={"valeur":("motif1", "motif2","motif3","motif4"),
"valeur2":("test1","test2","test3")}