dialog_documentation.py 992 B

12345678910111213141516171819202122232425262728293031
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. with ui.dialog() as dialog, ui.card():
  5. ui.label('Hello world!')
  6. ui.button('Close', on_click=dialog.close)
  7. ui.button('Open a dialog', on_click=dialog.open)
  8. def more() -> None:
  9. @text_demo('Awaitable dialog', '''
  10. Dialogs can be awaited.
  11. Use the `submit` method to close the dialog and return a result.
  12. Canceling the dialog by clicking in the background or pressing the escape key yields `None`.
  13. ''')
  14. def async_dialog_demo():
  15. with ui.dialog() as dialog, ui.card():
  16. ui.label('Are you sure?')
  17. with ui.row():
  18. ui.button('Yes', on_click=lambda: dialog.submit('Yes'))
  19. ui.button('No', on_click=lambda: dialog.submit('No'))
  20. async def show():
  21. result = await dialog
  22. ui.notify(f'You chose {result}')
  23. ui.button('Await a dialog', on_click=show)