Selector

class pygame_menu.widgets.Selector(label, elements, selector_id='', default=0, onchange=None, onreturn=None, *args, **kwargs)[source]

Bases: pygame_menu.widgets.core.widget.Widget

Selector widget.

Parameters:
  • label (str) – Selector label text
  • elements (list) – Elements of the selector
  • selector_id (str) – ID of the selector
  • default (int) – Index of default element to display
  • onchange (callable, None) – Callback when changing the selector
  • onreturn (callable, None) – Callback when pressing return button
  • kwargs (any) – Optional keyword-arguments for callbacks
draw(surface)[source]

Draw the widget shape.

Parameters:surface (pygame.Surface) – Surface to draw
Returns:None
get_value()[source]

Return the current value of the selector at the selected index.

Returns:Value and index as a tuple, (value, index)
Return type:tuple
left()[source]

Move selector to left.

Returns:None
right()[source]

Move selector to right.

Returns:None
set_value(item)[source]

Set the current value of the widget, selecting the element that matches the text if item is a string, or the index of the position of item is an integer.

For example, if selector is [[‘a’,0],[‘b’,1],[‘a’,2]]:
  • widget.set_value(‘a’) -> Widget selects 0 (first match)
  • widget.set_value(2) -> Widget selects 2.
Parameters:item (str, int) – Item to select, can be a string or an integer.
Returns:None
update(events)[source]

Update internal variable according to the given events list and fire the callbacks.

Parameters:events (list[pygame.event.Event]) – List of pygame events
Returns:True if updated
Return type:bool
update_elements(elements)[source]

Update selector elements.

Parameters:elements (Object) – Elements of the selector
Returns:None