msticpy.nbwidgets.option_buttons module
Module for pre-defined widget layouts.
- class msticpy.nbwidgets.option_buttons.OptionButtons(description: str | None = 'Select an option to continue', buttons: Iterable[str] | None = None, default: str | None = None, timeout: int = 0, debug: bool = False, **kwargs)
Bases:
IPyDisplayMixin
OptionButtons creates a sequence of buttons to choose from.
The widget can be run in synchronous mode as a simple option selector or in async mode with a timeout. In the latter mode, after the timeout has expired the widget value is set to the default option button value. To use the async mode you must call widget.display_async() with the async keyword.
- value
The value of the option selected (case-normalized)
- Type:
str
Example
>>> opt = OptionButtons(description="Continue something?", ... buttons=["Maybe", "Yes", "Cancel"], timeout=10) >>> await opt.display_async()
Initialize the OptionButton widget.
- Parameters:
description (Optional[str], optional) – Description label displayed above the buttons, by default “Select an option to continue”
buttons (Optional[Iterable[str]], optional) – A list of button values, by default None. This will default to [“Yes”, “No”, “Cancel”] “options” is an alias for this parameter.
default (Optional[str], optional) – The default value to use on timeout, by default the first value in the buttons list
timeout (int, optional) – Timeout in seconds, by default 0
debug (bool, optional) – Adds some debug information to an Output controle, by default False
- display()
Display the interactive widgets.
- async display_async(reset: bool = False)
Display widget with timeout.
- Parameters:
reset (bool, optional) – Resets any current value to None, by default False
- property layout
Create layout for buttons.