input.py 671 B

123456789101112131415161718192021
  1. import justpy as jp
  2. from typing import Callable, Literal, Union
  3. from .element import Element
  4. from ..utils import handle_exceptions, provide_arguments
  5. class Input(Element):
  6. def __init__(self,
  7. placeholder: str = None,
  8. value: Union[str, float] = None,
  9. type: Literal['text', 'number'] = 'text',
  10. on_change: Callable = None):
  11. view = jp.QInput(placeholder=placeholder, type=type)
  12. if value is not None:
  13. view.value = value
  14. if on_change is not None:
  15. view.on('input', handle_exceptions(provide_arguments(on_change, 'value')))
  16. super().__init__(view)