Python Forum
Can't get tkinter database aware cascading comboboxes to update properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't get tkinter database aware cascading comboboxes to update properly
#4
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:
cboTask["values"] = data
Did 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()
Reply


Messages In This Thread
RE: Can't get tkinter database aware cascading comboboxes to update properly - by deanhystad - Jan-11-2022, 05:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 21,201 Dec-02-2023, 07:05 PM
Last Post: aynous19
  Auto update database view jnik 0 472 Oct-31-2023, 04:26 PM
Last Post: jnik
  [Tkinter] TKINTER quiz using sqlite3 database hezza_23 45 21,855 Nov-29-2021, 09:42 PM
Last Post: Hilal
  [Tkinter] Update variable using tkinter entry methon drSlump 6 5,292 Oct-15-2021, 08:01 AM
Last Post: drSlump
  Linking Comboboxes MrP 24 7,374 Feb-03-2021, 10:59 PM
Last Post: MrP
  Print Values from a Sequence of Entries / ComboBoxes MC2020 4 2,860 Mar-28-2020, 10:05 PM
Last Post: MC2020
  Want to dynamically update numbers using tkinter in pygame script k0gane 0 2,100 Feb-09-2020, 09:01 AM
Last Post: k0gane
  Unable to update or refresh label text in tkinter jenkins43 3 6,705 Jul-24-2019, 02:09 PM
Last Post: Friend
  [PyQt] making dependant comboBoxes Hitsugaya 3 5,059 May-23-2019, 06:05 PM
Last Post: Alfalfa
  Tkinter - Make changes to graph and update it adriancovaci 0 6,636 Apr-08-2019, 09:02 AM
Last Post: adriancovaci

Forum Jump:

User Panel Messages

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