I am currently trying to code a programme with 3 comboboxes which are populated. For an example when the user picks "a" in the first combobox a new combobox should appear with new choices when "next" is pressed. Again the user puts in a value in the second combobox and presses "next", here a new combobox should appear with new choices. But somehow i cannot manage to show the third combobox.
Below the code is stated.
from tkinter import ttk
from tkinter import Tk
root = Tk()
root.geometry("400x400")
cmb = ttk.Combobox(root, width="10", values=['a','b'])
def checkcmbo():
if cmb.get() == "a":
cmb2 = ttk.Combobox(root, width="10", values=['aa','ab'])
cmb2.place(relx="0.1",rely="0.2")
if cmb2.get() == "aa":
cmb3 = ttk.Combobox(root, width="10", values=['car1','car2','car3'])
cmb3.place(relx="0.1",rely="0.3")
if cmb2.get() == "ab":
cmb3 = ttk.Combobox(root, width="10", values=['ship1','ship2','ship3'])
cmb3.place(relx="0.1",rely="0.3")
if cmb.get() == "b":
cmb2 = ttk.Combobox(root, width="10", values=['ba','bb'])
cmb2.place(relx="0.1",rely="0.2")
if cmb2.get() == "ba":
cmb3 = ttk.Combobox(root, width="10", values=['racecar1','racecar2','racecar3'])
cmb3.place(relx="0.1",rely="0.3")
if cmb2.get() == "ab":
cmb3 = ttk.Combobox(root, width="10", values=['reaceship1','raceship2','raceship3'])
cmb3.place(relx="0.1",rely="0.3")
cmb.place(relx="0.1",rely="0.1")
btn = ttk.Button(root, text="Next",command=checkcmbo)
btn.place(relx="0.5",rely="0.1")
root.mainloop()
Comboboxwidget and assign it to yourcmb2.So every timecmb2.get()is"".<<ComboboxSelected>>event oncmbandcmb2to change the options ofcmb2andcmb3respectively inside the event callback.<<ComboboxSelected>>event on a combobox, the event callback will be executed whenever an item of the combobox is selected. So you can populate another combobox in the event callback based on the selected item.