FunctionItem

Bases: cursesmenu.items.ExternalItem

class cursesmenu.items.FunctionItem(text, function, args=None, kwargs=None, menu=None, *, should_exit=False, override_index=None)[source]

A menu item that executes a Python function with arguments.

Parameters:
  • text (str) – The text of the item

  • function (Callable[..., Any]) – A function or lambda to be executed when the item is selected

  • args (Optional[list[Any]]) – A list of poitional arguments to be passed to the function

  • kwargs (Optional[dict[Any, Any]]) – A dict of kwargs to be passed to the function

  • menu (Optional[CursesMenu]) – The menu that this item belongs to

  • should_exit (bool) – Whether the menu will exit when this item is selected

action()[source]

Call the function with the provided arguments.

Return type:

None

get_return()[source]

Get the returned value from the function.

Return type:

Any

Returns:

The value returned from the function, or None if it hasn’t been called.