1
0

main.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. from nicegui import ui
  3. # define a list of URLs to be used as the image source in the UI
  4. image_urls = [
  5. 'https://picsum.photos/300/300?1',
  6. 'https://picsum.photos/300/300?2',
  7. 'https://picsum.photos/300/300?3',
  8. ]
  9. # create a dictionary to store the tab panels
  10. tabs = {}
  11. # function to switch tab panels
  12. def switch_tab(value):
  13. tabs['panels'].value = value
  14. # create tab_bar object without rendering it in the UI
  15. tab_bar = ui.tabs()
  16. # create a footer that is initially hidden
  17. with ui.footer(value=False) as footer:
  18. ui.label('Footer') # add a label to the footer
  19. # create a sticky button in the bottom-right of the page to toggle the footer
  20. with ui.page_sticky(position='bottom-right', x_offset=20, y_offset=20):
  21. ui.button(on_click=footer.toggle, icon='contact_support').props('fab')
  22. # create tab panels associated with the tab_bar
  23. with ui.tab_panels(tab_bar, value='A').classes('w-full') as panels:
  24. tabs['panels'] = panels
  25. # define the first tab panel 'A'
  26. with ui.tab_panel('A') as tabA:
  27. ui.label('Content of A').classes('text-center') # add a centered label
  28. # create a card with image and navigation buttons
  29. with ui.card().classes('m-4 p-4 shadow-lg w-128 h-64 relative'):
  30. with ui.card().classes('w-full h-full absolute'):
  31. ui.image(image_urls[0]).classes('w-full h-full') # display image
  32. # create navigation buttons to switch between tab panels
  33. ui.button(on_click=lambda: switch_tab('C'), icon='arrow_back').classes('absolute top-1/2 left-2')
  34. ui.button(on_click=lambda: switch_tab('B'), icon='arrow_forward').classes('absolute top-1/2 right-2')
  35. # define the second tab panel 'B'
  36. with ui.tab_panel('B') as tabB:
  37. ui.label('Content of B').classes('text-center') # add a centered label
  38. # create a card with image and navigation buttons
  39. with ui.card().classes('m-4 p-4 shadow-lg w-128 h-64 relative'):
  40. with ui.card().classes('w-full h-full absolute'):
  41. ui.image(image_urls[1]).classes('w-full h-full') # display image
  42. # create navigation buttons to switch between tab panels
  43. ui.button(on_click=lambda: switch_tab('C'), icon='arrow_forward').classes('absolute top-1/2 right-2')
  44. ui.button(on_click=lambda: switch_tab('A'), icon='arrow_back').classes('absolute top-1/2 left-2')
  45. # define the third tab panel 'C'
  46. with ui.tab_panel('C') as tabC:
  47. ui.label('Content of C').classes('text-center') # add a centered label
  48. # create a card with image and navigation buttons
  49. with ui.card().classes('m-4 p-4 shadow-lg w-128 h-64 relative'):
  50. with ui.card().classes('w-full h-full absolute'):
  51. ui.image(image_urls[2]).classes('w-full h-full') # display image
  52. # create navigation buttons to switch between tab panels
  53. ui.button(on_click=lambda: switch_tab('A'), icon='arrow_forward').classes('absolute top-1/2 right-2')
  54. ui.button(on_click=lambda: switch_tab('B'), icon='arrow_back').classes('absolute top-1/2 left-2')
  55. # run the UI
  56. ui.run()