MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / Menu

Class Menu

PySimpleGUI/PySimpleGUI.py:8534–8686  ·  view source on GitHub ↗

Menu Element is the Element that provides a Menu Bar that goes across the top of the window, just below titlebar. Here is an example layout. The "&" are shortcut keys ALT+key. Is a List of - "Item String" + List Where Item String is what will be displayed on the Menubar itself.

Source from the content-addressed store, hash-verified

8532# Menu #
8533# ---------------------------------------------------------------------- #
8534class Menu(Element):
8535 """
8536 Menu Element is the Element that provides a Menu Bar that goes across the top of the window, just below titlebar.
8537 Here is an example layout. The "&" are shortcut keys ALT+key.
8538 Is a List of - "Item String" + List
8539 Where Item String is what will be displayed on the Menubar itself.
8540 The List that follows the item represents the items that are shown then Menu item is clicked
8541 Notice how an "entry" in a mennu can be a list which means it branches out and shows another menu, etc. (resursive)
8542 menu_def = [['&File', ['!&Open', '&Save::savekey', '---', '&Properties', 'E&xit']],
8543 ['!&Edit', ['!&Paste', ['Special', 'Normal', ], 'Undo'], ],
8544 ['&Debugger', ['Popout', 'Launch Debugger']],
8545 ['&Toolbar', ['Command &1', 'Command &2', 'Command &3', 'Command &4']],
8546 ['&Help', '&About...'], ]
8547 Important Note! The colors, font, look of the Menubar itself cannot be changed, only the menus shown AFTER clicking the menubar
8548 can be changed. If you want to change the style/colors the Menubar, then you will have to use the MenubarCustom element.
8549 Finally, "keys" can be added to entries so make them unique. The "Save" entry has a key associated with it. You
8550 can see it has a "::" which signifies the beginning of a key. The user will not see the key portion when the
8551 menu is shown. The key portion is returned as part of the event.
8552 """
8553
8554 def __init__(self, menu_definition, background_color=None, text_color=None, disabled_text_color=None, size=(None, None), s=(None, None), tearoff=False,
8555 font=None, pad=None, p=None, key=None, k=None, visible=True, metadata=None):
8556 """
8557 :param menu_definition: The Menu definition specified using lists (docs explain the format)
8558 :type menu_definition: List[List[Tuple[str, List[str]]]
8559 :param background_color: color of the background of menus, NOT the Menubar
8560 :type background_color: (str)
8561 :param text_color: text color for menus, NOT the Menubar. Can be in #RRGGBB format or a color name "black".
8562 :type text_color: (str)
8563 :param disabled_text_color: color to use for text when item in submenu, not the menubar itself, is disabled. Can be in #RRGGBB format or a color name "black"
8564 :type disabled_text_color: (str)
8565 :param size: Not used in the tkinter port
8566 :type size: (int, int)
8567 :param s: Same as size parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, size will be used
8568 :type s: (int, int) | (None, None)
8569 :param tearoff: if True, then can tear the menu off from the window ans use as a floating window. Very cool effect
8570 :type tearoff: (bool)
8571 :param pad: Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int)
8572 :type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
8573 :param p: Same as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
8574 :type p: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
8575 :param font: specifies the font family, size, etc. of submenus. Does NOT apply to the Menubar itself. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
8576 :type font: (str or (str, int[, str]) or None)
8577 :param key: Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window
8578 :type key: str | int | tuple | object
8579 :param k: Same as the Key. You can use either k or key. Which ever is set will be used.
8580 :type k: str | int | tuple | object
8581 :param visible: set visibility state of the element
8582 :type visible: (bool)
8583 :param metadata: User metadata that can be set to ANYTHING
8584 :type metadata: (Any)
8585 """
8586
8587 self.BackgroundColor = background_color if background_color is not None else theme_input_background_color()
8588 self.TextColor = text_color if text_color is not None else theme_input_text_color()
8589
8590 self.DisabledTextColor = disabled_text_color if disabled_text_color is not None else COLOR_SYSTEM_DEFAULT
8591 self.MenuDefinition = copy.deepcopy(menu_definition)

Callers 2

make_windowFunction · 0.85
_create_main_windowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected