main.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. from router import Router
  3. from nicegui import ui
  4. router = Router()
  5. @router.add('/')
  6. async def show_one():
  7. ui.label('Content One').classes('text-2xl')
  8. @router.add('/two')
  9. async def show_two():
  10. ui.label('Content Two').classes('text-2xl')
  11. @router.add('/three')
  12. async def show_three():
  13. ui.label('Content Three').classes('text-2xl')
  14. @ui.page('/') # normal index page (eg. the entry point of the app)
  15. @ui.page('/{_:path}') # all other pages will be handled by the router but must be registered to also show the SPA index page
  16. async def main():
  17. # adding some navigation buttons to switch between the different pages
  18. with ui.row():
  19. ui.button('One', on_click=lambda: router.open(show_one)).classes('w-32')
  20. ui.button('Two', on_click=lambda: router.open(show_two)).classes('w-32')
  21. ui.button('Three', on_click=lambda: router.open(show_three)).classes('w-32')
  22. # this places the content which should be displayed
  23. router.frame().classes('w-full p-4 bg-gray-100')
  24. ui.run()