query_documentation.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.query)
  4. def main_demo() -> None:
  5. def set_background(color: str) -> None:
  6. ui.query('body').style(f'background-color: {color}')
  7. # ui.button('Blue', on_click=lambda: set_background('#ddeeff'))
  8. # ui.button('Orange', on_click=lambda: set_background('#ffeedd'))
  9. # END OF DEMO
  10. ui.button('Blue', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ddeeff'))
  11. ui.button('Orange', on_click=lambda e: e.sender.parent_slot.parent.style('background-color: #ffeedd'))
  12. @doc.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. ui.context.slot_stack[-1].parent.classes('bg-gradient-to-t from-blue-400 to-blue-100')
  20. @doc.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. ui.context.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')
  31. doc.reference(ui.query)