Jan-11-2022, 05:54 PM
I'm not sure that I understand your question. This is my attempt to answer this question: "I have two combo boxes. When I change the value in one of the combo boxes I want to change the choices displayed in a second combo box." If that is the wrong question please clarify.
Where is the code where you update the fields in the combo box? Each time you want a combo box to list different values you need to do something like this:
Where is the code where you update the fields in the combo box? Each time you want a combo box to list different values you need to do something like this:
cboTask["values"] = dataDid you leave this part out of your post, or is this what you are missing? In this example changing the abox selection loads a different set of values in bbox.
import tkinter as tk from tkinter import ttk """Mapping of bbox choices based on abox selection""" choices = { "A":["1", "2", "3"], "B":["4", "6", "7"], "C":["8", "8", "9"], } def aselected(box, var, values): """I get called when the abox selection changes""" box["values"] = values var.set(values[0]) root = tk.Tk() key = list(choices.keys())[0] value = choices[key] avar = tk.StringVar(value=key) bvar = tk.StringVar(value=value[0]) abox = ttk.Combobox(root, textvariable=avar, values=list(choices.keys())) bbox = ttk.Combobox(root, textvariable=bvar, values=value) abox.bind('<<ComboboxSelected>>', lambda event: aselected(bbox, bvar, choices[avar.get()])) bbox.bind('<<ComboboxSelected>>', lambda event: print(bvar.get())) abox.pack() bbox.pack() root.mainloop()