0

We are trying to make a simple GUI for our HR department. We are using tkinter with PyAD and subprocess. I am trying to create a dynamic OptionMenu based on a "selection" in the previous OptionMenu.

For example: "Department" OptionMenu {"Warehouse", "Office", "Shipping"} >>> The "Job" OptionMenu would change accordingly "Warehouse" is selected "Job" OptionMenu would show {"Pallet Jack", "High Lift", "Stand Up"}.

I have hard coded the warehouse positions due to that department having the most hires.

depts = { 'Warehouse','Office','HR','IT','Maintenance'}
dept_var.set('DEPT') # set the default option


jobs = {'Pallet Jack', 'General Labor', 'Sit Down', 'Stand Up', 'Highlift'}
job_var.set('JOB')

popupMenu1 = OptionMenu(mainframe, dept_var, *depts)

popupMenu1.grid(row = 2, column =1)

popupMenu2 = OptionMenu(backframe, job_var, *jobs)

popupMenu2.grid(row = 2, column =1)
FrainBr33z3
  • 1,085
  • 1
  • 6
  • 12

1 Answers1

1

You need to add a command option to popupMenu1 and do the changes for popupMenu2 in this command function, as follows:

popupMenu1 = OptionMenu(root, dept_var, *depts, command=change_job_menu)

and the function change_job_menu as:

def change_job_menu(value):
    popupMenu2['menu'].delete(0, END)

    if dept_var.get() == 'Warehouse':
        new_menu = {"Pallet Jack", "High Lift", "Stand Up"}
        for i in new_menu:
            popupMenu2['menu'].add_command(label=i, command=tk._setit(job_var, i))
FrainBr33z3
  • 1,085
  • 1
  • 6
  • 12