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
JavaScript
x
8
1
[location[rack 1,[Shelf 1, [Bin A, Bin B, Bin C, Bin D, Bin E]
2
Shelf 2, [Locations ]
3
Shelf 3, [Locations ]
4
Shelf 4, [Locations ]]
5
rack 2,[so on]
6
7
]]
8
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
JavaScript
1
29
29
1
import PySimpleGUI as sg
2
3
menu_def = ['Location',
4
[
5
'Rack 1',
6
[
7
'Shelf 1', ['Bin A::11', 'Bin B::11'],
8
'Shelf 2', ['Bin A::12', 'Bin B::12'],
9
],
10
'Rack 2',
11
[
12
'Shelf 1', ['Bin A::21', 'Bin B::21'],
13
'Shelf 2', ['Bin A::22', 'Bin B::22'],
14
],
15
]
16
]
17
18
layout = [[sg.ButtonMenu('Location', menu_def=menu_def, key='Button_Menu')]]
19
window = sg.Window('Title', layout)
20
21
while True:
22
event, values = window.read()
23
if event == sg.WIN_CLOSED:
24
break
25
elif event == 'Button_Menu':
26
print(values[event])
27
28
window.close()
29