input.py 965 B

1234567891011121314151617181920212223242526272829
  1. import justpy as jp
  2. from typing import Awaitable, Callable, Optional, Union
  3. from .string_element import StringElement
  4. class Input(StringElement):
  5. def __init__(self,
  6. label: str = None,
  7. *,
  8. placeholder: str = None,
  9. value: str = '',
  10. on_change: Optional[Union[Callable, Awaitable]] = None,
  11. ):
  12. """Text Input Element
  13. :param label: displayed label for the text input
  14. :param placeholder: text to show if no value is entered
  15. :param value: the current value of the text input
  16. :param on_change: callback to execute when the input is confirmed by leaving the focus
  17. """
  18. view = jp.QInput(
  19. label=label,
  20. placeholder=placeholder,
  21. value=value,
  22. change=self.handle_change,
  23. temp=False,
  24. )
  25. super().__init__(view, value=value, on_change=on_change)