MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / Menubar

Function Menubar

DemoPrograms/Demo_Menubar_Custom_and_Traditional.py:25–52  ·  view source on GitHub ↗

A User Defined element that simulates a Menu element by using ButtonMenu elements :param menu_def: A standard PySimpleGUI menu definition :type menu_def: List[List[Tuple[str, List[str]]] :param text_color: color for the menubar's text :type text_color: :param background_col

(menu_def, text_color, background_color, pad=(0, 0))

Source from the content-addressed store, hash-verified

23sg.MENU_SHORTCUT_CHARACTER = '&'
24
25def Menubar(menu_def, text_color, background_color, pad=(0, 0)):
26 """
27 A User Defined element that simulates a Menu element by using ButtonMenu elements
28
29 :param menu_def: A standard PySimpleGUI menu definition
30 :type menu_def: List[List[Tuple[str, List[str]]]
31 :param text_color: color for the menubar's text
32 :type text_color:
33 :param background_color: color for the menubar's background
34 :type background_color:
35 :param pad: Amount of padding around each menu entry
36 :type pad:
37 :return: A column element that has a row of ButtonMenu buttons
38 :rtype: sg.Column
39 """
40 row = []
41 for menu in menu_def:
42 text = menu[0]
43 if sg.MENU_SHORTCUT_CHARACTER in text:
44 text = text.replace(sg.MENU_SHORTCUT_CHARACTER, '')
45 if text.startswith(sg.MENU_DISABLED_CHARACTER):
46 disabled = True
47 text = text[len(sg.MENU_DISABLED_CHARACTER):]
48 else:
49 disabled = False
50 row += [sg.ButtonMenu(text, menu, border_width=0, button_color=f'{text_color} on {background_color}',key=text, pad=pad, disabled=disabled)]
51
52 return sg.Column([row], background_color=background_color, pad=(0,0), expand_x=True)
53
54def main():
55 sg.theme('dark green 7')

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected