I am trying to setup dynamic dropdown menus for the app that I am writing. I am having a hard time updating the secondary dropdown when an option is selected on the Primary. I and not sure if I should be using a for loop in this situation or need to look at a different option all together.
import tkinter as tk
primary = [
'option 1',
'option 2',
'option 3',
'option 4'
]
options1 = [
'option 1.1',
'option 1.2',
'option 1.3',
'option 1.4'
]
options2 = [
'option 2.1',
'option 2.2',
'option 2.3',
'option 2.4'
]
secondary = options1
#Window builder
window = tk.Tk()
window.geometry('400x200')
#Primary Drop Down Options
primDD = tk.StringVar()
primDD.set(primary[0])
primOpt = tk.OptionMenu(window, primDD, *primary)
#secondary Selector
if primDD.get() == 'options 1':
secondary = options1
elif primDD.get() == 'options 2':
secondary = options2
#Secondary Drop Down Options
secDD = tk.StringVar()
secDD.set(secondary[0])
secOpt = tk.OptionMenu(window, secDD, *secondary)
#Window Layout
primOpt.config(width=20)
secOpt.config(width=30)
primOpt.grid(row=0, column=0, padx=1.25, pady=1.25)
secOpt.grid(row=0, column=1, padx=1.25, pady=1.25)
window.mainloop()