main.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. from typing import Dict
  3. from nicegui import ui
  4. tab_names = ['A', 'B', 'C']
  5. # necessary until we improve native support for tabs (https://github.com/zauberzeug/nicegui/issues/251)
  6. def switch_tab(msg: Dict) -> None:
  7. name = msg['args']
  8. tabs.props(f'model-value={name}')
  9. panels.props(f'model-value={name}')
  10. with ui.header().classes(replace='row items-center') as header:
  11. ui.button(on_click=lambda: left_drawer.toggle()).props('flat color=white icon=menu')
  12. with ui.element('q-tabs').on('update:model-value', switch_tab) as tabs:
  13. for name in tab_names:
  14. ui.element('q-tab').props(f'name={name} label={name}')
  15. with ui.footer(value=False) as footer:
  16. ui.label('Footer')
  17. with ui.left_drawer().classes('bg-blue-100') as left_drawer:
  18. ui.label('Side menu')
  19. with ui.page_sticky(position='bottom-right', x_offset=20, y_offset=20):
  20. ui.button(on_click=footer.toggle).props('fab icon=contact_support')
  21. # the page content consists of multiple tab panels
  22. with ui.element('q-tab-panels').props('model-value=A animated').classes('w-full') as panels:
  23. for name in tab_names:
  24. with ui.element('q-tab-panel').props(f'name={name}').classes('w-full'):
  25. ui.label(f'Content of {name}')
  26. ui.run()