MenuBar¶
-
class
pygame_menu.widgets.
MenuBar
(title, width, background_color, back_box=False, mode=1000, onchange=None, onreturn=None, *args, **kwargs)[source]¶ Bases:
pygame_menu.widgets.core.widget.Widget
MenuBar widget.
Parameters: - title (str) – Title of the menubar
- width (int, float) – Width of the widget, generally width of the Menu
- background_color (tuple, list) – Background color
- back_box (bool) – Draw a back-box button on header
- mode (int) – Mode of drawing the bar
- onchange (callable, None) – Callback when changing the selector
- onreturn (callable, None) – Callback when pressing return button
- args (any) – Optional arguments for callbacks
- kwargs (any) – Optional keyword-arguments for callbacks
-
apply
(*args)¶ Run
on_return
callback when return event. A callback function receives the following arguments:callback_func( value, *args, *widget._args, **widget._kwargs )
- with:
value
(if something is returned byget_value()
)args
given to this methodargs
of the widgetkwargs
of the widget
Parameters: args – Extra arguments passed to the callback Returns: None
-
change
(*args)¶ Run
on_change
callback after change event is triggered. A callback function receives the following arguments:callback_func( value, *args, *widget._args, **widget._kwargs )
- with:
value
(if something is returned byget_value()
)args
given to this methodargs
of the widgetkwargs
of the widget
Parameters: args – Extra arguments passed to the callback Returns: None
-
draw
(surface)[source]¶ Draw the widget shape.
Parameters: surface ( pygame.Surface
) – Surface to drawReturns: None
-
draw_selection
(surface)¶ Draw selection effect on widget.
Parameters: surface ( pygame.Surface
) – Surface to drawReturns: None
-
get_attribute
(key, default)¶ Get attribute value.
Parameters: - key (str) – Key of the attribute
- default (Any) – Value if does not exists
Returns: Attribute data
Return type: Any
-
get_font_info
()¶ Return a dict with the information of the widget font.
Returns: Dict, keys: size (int), name (str), color (tuple), selected_color (tuple), antialias (bool) Return type: dict
-
get_menu
()¶ Return menu reference (if exists).
Returns: Menu reference Return type: pygame_menu.Menu
-
get_rect
()¶ Return the Rect object, this forces the widget rendering
Returns: Widget rect Return type: pygame.Rect
-
get_selected_time
()¶ Return time the widget has been selected in miliseconds. If the widget is not currently selected, return 0.
Returns: Time in ms Return type: float
-
get_selection_effect
()¶ Returns: Selection effect Return type: pygame_menu.widgets.core.Selection
-
get_value
()¶ Return the value. If exception
ValueError
is raised, no value will be passed to the callbacks.Returns: Value Return type: Object
-
set_alignment
(align)¶ Set the alignment of the widget.
Parameters: align (str) – Widget align, see locals Returns: None
-
set_attribute
(key, value)¶ Set widget attribute.
Parameters: - key (str) – Key of the attribute
- value (Any) – Value of the attribute
Returns: None
-
set_background_color
(color, inflate=(0, 0))¶ Set widget background color.
Parameters: - color (tuple, list,
pygame_menu.baseimage.BaseImage
, None) – Widget background color - inflate (tuple, list) – Inflate background in x,y
Returns: None
- color (tuple, list,
-
set_controls
(joystick=True, mouse=True)¶ Enable interfaces to control the widget.
Parameters: Returns: None
-
set_font
(font, font_size, color, selected_color, background_color, antialias=True)¶ Set the text font.
Parameters: - font (str, list) – Name or list of names for font (see pygame.font.match_font for precise format)
- font_size (int) – Size of font in pixels
- color (tuple) – Text color
- selected_color (tuple) – Text color when widget is selected
- background_color (tuple) – Font background color
- antialias (bool) – Determines if antialias is applied to font (uses more processing power)
Returns: None
-
set_margin
(x, y)¶ Set Widget margin.
Parameters: Returns: None
-
set_max_width
(width)¶ Set widget max width (column support) if force_fit_text is enabled.
Parameters: width (int, float, None) – Width in px, None if max width is disabled Returns: None
-
set_menu
(menu)¶ Set menu reference.
Parameters: menu ( pygame_menu.Menu
) – Menu objectReturns: None
-
set_position
(posx, posy)¶ Set the position.
Parameters: Returns: None
-
set_selected
(selected=True)¶ Mark the widget as selected.
Parameters: selected (bool) – Set item as selected Returns: None
-
set_selection_effect
(selection)¶ Set the selection effect handler.
Parameters: selection ( pygame_menu.widgets.core.Selection
) – Selection effect classReturns: None
-
set_shadow
(enabled=True, color=None, position=None, offset=None)¶ Show text shadow.
Parameters: Returns: None
-
set_sound
(sound)¶ Set sound engine to the widget.
Parameters: sound ( pygame_menu.sound.Sound
) – Sound objectReturns: None
-
set_value
(value)¶ Set the value.
Warning
This method does not fire the callbacks as it is called programmatically. This behavior is deliberately chosen to avoid infinite loops.
Parameters: value (Object) – Value to be set on the widget Returns: None
-
surface_needs_update
()¶ Checks if the widget width/height has changed because events. If so, return true and set the status of the widget (menu widget position needs update) as false. This method is used by .update() from Menu class.
Returns: True if the widget position has changed by events after the rendering. Return type: bool