intro.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from nicegui import ui
  2. from .tools import main_page_demo
  3. def create_intro() -> None:
  4. @main_page_demo('Styling',
  5. 'While having reasonable defaults, you can still modify the look of your app with CSS as well as Tailwind and Quasar classes.')
  6. def formatting_demo():
  7. ui.icon('thumb_up')
  8. ui.markdown('This is **Markdown**.')
  9. ui.html('This is <strong>HTML</strong>.')
  10. with ui.row():
  11. ui.label('CSS').style('color: #888; font-weight: bold')
  12. ui.label('Tailwind').classes('font-serif')
  13. ui.label('Quasar').classes('q-ml-xl')
  14. ui.link('NiceGUI on GitHub', 'https://github.com/zauberzeug/nicegui')
  15. @main_page_demo('Common UI Elements',
  16. 'NiceGUI comes with a collection of commonly used UI elements.')
  17. def common_elements_demo():
  18. from nicegui.events import ValueChangeEventArguments
  19. def show(event: ValueChangeEventArguments):
  20. name = type(event.sender).__name__
  21. ui.notify(f'{name}: {event.value}')
  22. ui.button('Button', on_click=lambda: ui.notify('Click'))
  23. with ui.row():
  24. ui.checkbox('Checkbox', on_change=show)
  25. ui.switch('Switch', on_change=show)
  26. ui.radio(['A', 'B', 'C'], value='A', on_change=show).props('inline')
  27. with ui.row():
  28. ui.input('Text input', on_change=show)
  29. ui.select(['One', 'Two'], value='One', on_change=show)
  30. ui.link('And many more...', '/documentation').classes('mt-8')
  31. @main_page_demo('Value Binding',
  32. 'Binding values between UI elements and data models is built into NiceGUI.')
  33. def binding_demo():
  34. class Demo:
  35. def __init__(self):
  36. self.number = 1
  37. demo = Demo()
  38. v = ui.checkbox('visible', value=True)
  39. with ui.column().bind_visibility_from(v, 'value'):
  40. ui.slider(min=1, max=3).bind_value(demo, 'number')
  41. ui.toggle({1: 'A', 2: 'B', 3: 'C'}).bind_value(demo, 'number')
  42. ui.number().bind_value(demo, 'number')