radio.py 793 B

123456789101112131415161718192021
  1. import justpy as jp
  2. from typing import Awaitable, Callable, Dict, List, Optional, Union
  3. from .choice_element import ChoiceElement
  4. class Radio(ChoiceElement):
  5. def __init__(self,
  6. options: Union[List, Dict],
  7. *,
  8. value: any = None,
  9. on_change: Optional[Union[Callable, Awaitable]] = None,
  10. ):
  11. """Radio Selection Element
  12. :param options: a list ['value1', ...] or dictionary `{'value1':'label1', ...}` specifying the options
  13. :param value: the inital value
  14. :param on_change: callback to execute when selection changes
  15. """
  16. view = jp.QOptionGroup(options=options, input=self.handle_change)
  17. super().__init__(view, options, value=value, on_change=on_change)