Widget selection effects

Core Class

class pygame_menu.widgets.core.Selection(margin_left, margin_right, margin_top, margin_bottom)[source]

Widget selection effect class.

Note

All selection classes must be copyable.

Parameters
copy()[source]

Creates a deep copy of the object.

Return type

Selection

Returns

Copied selection effect

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

Selection

Returns

Self reference

get_background_color()[source]

Return the background color.

Return type

Union[Tuple[int, int, int], Tuple[int, int, int, int], BaseImage, None]

Returns

Background color or None

get_height()[source]

Return the selection height as sum of top and bottom margins.

Return type

int

Returns

Height in px

get_margin()[source]

Return the top, left, bottom and right margins of the selection.

Return type

Tuple[int, int, int, int]

Returns

Tuple of (top, left, bottom, right) margins in px

get_width()[source]

Return the selection width as sum of left and right margins.

Return type

int

Returns

Width in px

get_xy_margin()[source]

Return the x/y margins of the selection.

Return type

Tuple[int, int]

Returns

Margin tuple on x-axis and y-axis (x, y) in px

inflate(rect, inflate=None)[source]

Grow or shrink the rectangle size according to margins.

Parameters
Return type

Rect

Returns

Inflated rect

margin_xy(x, y)[source]

Set margins at left-right / top-bottom.

Parameters
Return type

Selection

Returns

Self reference

set_background_color(color)[source]

Set the selection background color. It will replace the background color of the widget if selected.

Parameters

color (Union[Tuple[int, int, int], Tuple[int, int, int, int], str, int, Color, BaseImage]) – Background color

Return type

Selection

Returns

Self reference

set_color(color)[source]

Set the selection effect color.

Parameters

color (Union[Tuple[int, int, int], Tuple[int, int, int, int], str, int, Color]) – Selection color

Return type

Selection

Returns

Self reference

zero_margin()[source]

Makes selection margin zero.

Return type

Selection

Returns

Self reference

Highlight Selection

class pygame_menu.widgets.HighlightSelection(border_width=1, margin_x=16, margin_y=8)[source]

Bases: pygame_menu.widgets.core.selection.Selection

Widget selection highlight class.

Note

Widget background color may not reach the entire selection area.

Parameters
  • border_width (int) – Border width of the highlight box (px)

  • margin_x (Union[int, float]) – X margin of selected highlight box (px)

  • margin_y (Union[int, float]) – Y margin of selected highlight box (px)

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

HighlightSelection

Returns

Self reference

Left Arrow Selection

class pygame_menu.widgets.LeftArrowSelection(arrow_size=(10, 15), arrow_right_margin=5, arrow_vertical_offset=0, blink_ms=0)[source]

Bases: pygame_menu.widgets.selection.arrow_selection.ArrowSelection

Widget selection left arrow class. Creates an arrow to the left of the selected Menu item.

Parameters
  • arrow_size (Tuple[int, int]) – Size of arrow on x-axis and y-axis (width, height) in px

  • arrow_right_margin (int) – Distance from the arrow to the widget (px)

  • arrow_vertical_offset (int) – Vertical offset of the arrow (px)

  • blink_ms (Union[int, float]) – Milliseconds between each blink; if 0 blinking is disabled

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

LeftArrowSelection

Returns

Self reference

None Selection

class pygame_menu.widgets.NoneSelection[source]

Bases: pygame_menu.widgets.selection.simple.SimpleSelection

No selection effect.

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

NoneSelection

Returns

Self reference

Right Arrow Selection

class pygame_menu.widgets.RightArrowSelection(arrow_size=(10, 15), arrow_left_margin=3, arrow_vertical_offset=0, blink_ms=0)[source]

Bases: pygame_menu.widgets.selection.arrow_selection.ArrowSelection

Widget selection right arrow class. Creates an arrow to the right of the selected Menu item.

Parameters
  • arrow_size (Tuple[int, int]) – Size of arrow on x-axis and y-axis (width, height) in px

  • arrow_left_margin (int) – Distance from the arrow to the widget (px)

  • arrow_vertical_offset (int) – Vertical offset of the arrow (px)

  • blink_ms (Union[int, float]) – Milliseconds between each blink; if 0 blinking is disabled

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

RightArrowSelection

Returns

Self reference

Simple Selection

class pygame_menu.widgets.SimpleSelection[source]

Bases: pygame_menu.widgets.core.selection.Selection

This selection effect only tells widget to apply selection color to font if selected.

draw(surface, widget)[source]

Draw the selection.

Parameters
  • surface (Surface) – Surface to draw

  • widget (Widget) – Widget object

Return type

SimpleSelection

Returns

Self reference