query_documentation.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from nicegui import globals, ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. def set_background(color: str) -> None:
  5. ui.query('body').style(f'background-color: {color}')
  6. # ui.button('Blue', on_click=lambda: set_background('#ddeeff'))
  7. # ui.button('Orange', on_click=lambda: set_background('#ffeedd'))
  8. # END OF DEMO
  9. ui.button('Blue', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ddeeff'))
  10. ui.button('Orange', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ffeedd'))
  11. def more() -> None:
  12. @text_demo('Set background gradient', '''
  13. It's easy to set a background gradient, image or similar.
  14. See [w3schools.com](https://www.w3schools.com/cssref/pr_background-image.php) for more information about setting background with CSS.
  15. ''')
  16. def background_image():
  17. # ui.query('body').classes('bg-gradient-to-t from-blue-400 to-blue-100')
  18. # END OF DEMO
  19. globals.get_slot_stack()[-1].parent.classes('bg-gradient-to-t from-blue-400 to-blue-100')
  20. @text_demo('Modify default page padding', '''
  21. By default, NiceGUI provides a built-in padding around the content of the page.
  22. You can modify it using the class selector `.nicegui-content`.
  23. ''')
  24. def remove_padding():
  25. # ui.query('.nicegui-content').classes('p-0')
  26. globals.get_slot_stack()[-1].parent.classes(remove='p-4') # HIDE
  27. # with ui.column().classes('h-screen w-full bg-gray-400 justify-between'):
  28. with ui.column().classes('h-full w-full bg-gray-400 justify-between'): # HIDE
  29. ui.label('top left')
  30. ui.label('bottom right').classes('self-end')