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))
| 23 | sg.MENU_SHORTCUT_CHARACTER = '&' |
| 24 | |
| 25 | def 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 | |
| 54 | def main(): |
| 55 | sg.theme('dark green 7') |