button.py 596 B

12345678910111213141516171819
  1. from typing import Callable
  2. import justpy as jp
  3. from .element import Element
  4. from ..utils import handle_exceptions, provide_arguments
  5. class Button(Element):
  6. def __init__(self, text: str, icon: str = None, icon_right: str = None, on_click: Callable = None):
  7. view = jp.QButton(label=text, color='primary')
  8. if icon is not None:
  9. view.icon = icon
  10. if icon_right is not None:
  11. view.icon_right = icon_right
  12. if on_click is not None:
  13. view.on('click', handle_exceptions(provide_arguments(on_click)))
  14. super().__init__(view)