pygame-menu Logo

First steps

  • Creating menus
  • Adding widgets
  • Adding sounds
  • Creating themes
  • Gallery / Examples

Advanced usage

  • Package organization
  • Create a widget
  • Create a selection effect
  • Decorate a Menu / Widgets
  • Configure controller
  • Widget selection effects

Menu APIs

  • BaseImage
  • ScrollArea

Widgets API

  • Button
  • ColorInput
  • DropSelect
  • DropSelectMultiple
  • Frame
  • HMargin
  • Image
  • Label
  • MenuBar
  • MenuLink
    • MenuLink
      • MenuLink.force_menu_surface_cache_update()
      • MenuLink.force_menu_surface_update()
      • MenuLink.get_attribute()
      • MenuLink.get_class_id()
      • MenuLink.get_col_row_index()
      • MenuLink.get_controller()
      • MenuLink.get_counter_attribute()
      • MenuLink.get_id()
      • MenuLink.get_menu()
      • MenuLink.get_scrollarea()
      • MenuLink.has_attribute()
      • MenuLink.hide()
      • MenuLink.is_floating()
      • MenuLink.is_visible()
      • MenuLink.on_remove_from_menu()
      • MenuLink.open()
      • MenuLink.remove_attribute()
      • MenuLink.render()
      • MenuLink.scroll_to_widget()
      • MenuLink.set_attribute()
      • MenuLink.set_col_row_index()
      • MenuLink.set_controller()
      • MenuLink.set_menu()
      • MenuLink.set_scrollarea()
      • MenuLink.shadow()
      • MenuLink.show()
      • MenuLink.update_menu()
  • NoneWidget
  • ProgressBar
  • RangeSlider
  • ScrollBar
  • Selector
  • SurfaceWidget
  • Table
  • TextInput
  • ToggleSwitch
  • VFill
  • VMargin

About pygame-menu

  • License
  • Contributors

Migration Guides

  • Migration Guide - v2 to v3
  • Migration Guide - v3 to v4
pygame-menu
  • MenuLink
  • View page source

MenuLink

class pygame_menu.widgets.MenuLink(menu, menu_opener_handler, link_id='')[source]

Bases: NoneWidget

Menu link widget; adds a link to another Menu. The behaviour is similar to a button, but this widget is invisible, and cannot be selectable.

Note

MenuLink does not accept transformations.

Parameters:
  • link_id (str) – Link ID

  • menu_opener_handler (Callable) – Callback for opening the menu object

  • menu (Menu) – Menu object

force_menu_surface_cache_update()

Forces menu surface cache to update after next drawing call. This also updates widget decoration.

Note

This method only updates the surface cache, without forcing re-rendering of all Menu widgets as pygame_menu.widgets.core.widget.Widget.force_menu_surface_update() does.

Return type:

Widget

Returns:

Self reference

force_menu_surface_update()

Forces menu surface update after next rendering call. This method automatically updates widget decoration cache as Menu render forces it to re-render.

This method also should be called by each widget after render.

Note

This method is expensive, as menu surface update forces re-rendering of all widgets (because them can change in size, position, etc…).

Return type:

Widget

Returns:

Self reference

get_attribute(key, default=None)

Get an attribute value.

Parameters:
  • key (str) – Key of the attribute

  • default (Optional[Any]) – Value if it does not exist

Return type:

Any

Returns:

Attribute data

get_class_id()

Return the Class+ID as a string.

Return type:

str

Returns:

Class+ID format

get_col_row_index()

Get the Widget column/row position.

Return type:

Tuple[int, int, int]

Returns:

(column, row, index) tuple

get_controller()

Return the widget controller. Each widget has their own controller object.

Return type:

Controller

Returns:

Controller object

get_counter_attribute(key, incr=0, default=0)

Get counter attribute.

Parameters:
  • key (str) – Key of the attribute

  • incr (Any) – Increase value

  • default (Any) – Default vale to start with, by default it’s zero

Return type:

Union[int, float]

Returns:

New increase value

get_id()

Return the object ID.

Return type:

str

Returns:

Object ID

get_menu()

Return the Menu reference, None if it has not been set.

Return type:

Optional[Menu]

Returns:

Menu reference

get_scrollarea()

Return the scrollarea object.

Return type:

ScrollArea

Returns:

ScrollArea object

has_attribute(key)

Return True if the object has the given attribute.

Parameters:

key (str) – Key of the attribute

Return type:

bool

Returns:

True if exists

hide()[source]

Hides the Widget.

Return type:

MenuLink

Returns:

Self reference

is_floating()

Return True if the Widget is floating.

Return type:

bool

Returns:

Float status

is_visible(check_frame=True)

Return True if the Widget is visible.

Parameters:

check_frame (bool) – If True check frame and sub-frames if they’re opened as well

Return type:

bool

Returns:

Visible status

on_remove_from_menu()

Function executed if the Widget is removed from the Menu.

Return type:

Widget

Returns:

Self reference

open()[source]

Open the menu link.

Return type:

None

remove_attribute(key)

Removes the given attribute from the object. Throws IndexError if the given key does not exist.

Parameters:

key (str) – Key of the attribute

Return type:

Base

Returns:

Self reference

render()

Public rendering method.

Note

Unlike private _render method, public method forces widget rendering (calling pygame_menu.widgets.core.widget.Widget._force_render()). Use this method only if the widget has changed the state. Running this function many times may affect the performance.

Note

Before rendering, check out if the widget font/title/values are set. If not, it is probable that a zero-size surface is set.

Return type:

Optional[bool]

Returns:

True if widget has rendered a new state, None if the widget has not changed, so render used a cache

scroll_to_widget(margin=(0, 0), scroll_parent=True)

The container ScrollArea scrolls to the Widget.

Parameters:
  • margin (Tuple[Union[int, float], Union[int, float]]) – Extra margin around the rect in px on x-axis and y-axis

  • scroll_parent (bool) – If True parent scroll also scrolls to widget

Return type:

Widget

Returns:

Self reference

set_attribute(key, value=None)

Set an attribute.

Parameters:
  • key (str) – Key of the attribute

  • value (Optional[Any]) – Value of the attribute

Return type:

Base

Returns:

Self reference

set_col_row_index(col, row, index)

Set the (column, row, index) position. If the column or row is -1 then the widget is not assigned to a certain column/row (for example, if it’s hidden).

Parameters:
  • col (int) – Column

  • row (int) – Row

  • index (int) – Index in Menu widget list

Return type:

Widget

Returns:

Self reference

set_controller(controller)

Set a new controller object.

Parameters:

controller (Controller) – Controller

Return type:

Widget

Returns:

Self reference

set_menu(menu)

Set the Widget menu reference.

Parameters:

menu (Optional[Menu]) – Menu object

Return type:

Widget

Returns:

Self reference

set_scrollarea(scrollarea)

Set scrollarea reference. Mostly used for events.

Parameters:

scrollarea (Optional[ScrollArea]) – Scrollarea object

Return type:

None

shadow(*args, **kwargs)

Configure the widget shadow.

Parameters:
  • shadow_type – Shadow type, it can be rectangular or ellipse

  • shadow_width – Shadow width in px. If 0 the shadow is disabled

  • corner_radius – Shadow corner radius if rectangular in px

  • color – Shadow color

  • aa_amount – Antialiasing amout

Return type:

NoneWidget

Returns:

Self reference

show()[source]

Set the Widget visible.

Return type:

MenuLink

Returns:

Self reference

update_menu(events)

Update the widget from Menu. This method is the same as update(), however, it takes into account the value of widget.receive_menu_update_events.

Parameters:

events (Union[List[Event], Tuple[Event]]) – List/Tuple of pygame events

Return type:

bool

Returns:

True if updated


© Copyright Copyright 2017 Pablo Pizarro R. @ppizarror.

Built with Sphinx using a theme provided by Read the Docs.