I’m looking for a drop down menu system to help control the flow for a variety of locations.
The structure would look like this
[location[rack 1,[Shelf 1, [Bin A, Bin B, Bin C, Bin D, Bin E]
Shelf 2, [Locations...]
Shelf 3, [Locations...]
Shelf 4, [Locations...]]
rack 2,[so on]
...
]]
I looked into Menus but that will force to the top of the window regardless of placement in the layout. I tried to throw the menu code (basically what you see above) as a combo and it just displayed all as one.
To get to the point of the question: Is there a way to do nested combo menus in pysimplegui, or do I need to do something else. And if so, what should should I be looking at for a reference?
Advertisement
Answer
Try ButtonMenu element, you can add “keys” to make menu items unique or as another way of identifying a menu item than the text shown. The key is added to the text portion by placing :: after the text.
Menu Item::key
import PySimpleGUI as sg
menu_def = ['Location',
[
'Rack 1',
[
'Shelf 1', ['Bin A::11', 'Bin B::11'],
'Shelf 2', ['Bin A::12', 'Bin B::12'],
],
'Rack 2',
[
'Shelf 1', ['Bin A::21', 'Bin B::21'],
'Shelf 2', ['Bin A::22', 'Bin B::22'],
],
]
]
layout = [[sg.ButtonMenu('Location', menu_def=menu_def, key='Button_Menu')]]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'Button_Menu':
print(values[event])
window.close()
