ui.icon
This element is based on Quasar's QIcon component.
Here is a reference of possible names.
name: | name of the icon (snake case, e.g. add_circle) |
---|---|
size: | size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem |
color: | icon color (either a Quasar, Tailwind, or CSS color or None, default: None) |
from nicegui import ui
ui.icon('thumb_up', color='primary').classes('text-5xl')
ui.run()
You can use different sets of Material icons and symbols. The Quasar documentation gives an overview of all available icon sets and their name prefix:
- None for filled icons
- "o_" for outline icons
- "r_" for round icons
- "s_" for sharp icons
- "sym_o_" for outline symbols
- "sym_r_" for round symbols
- "sym_s_" for sharp symbols
from nicegui import ui
with ui.row().classes('text-4xl'):
ui.icon('home')
ui.icon('o_home')
ui.icon('r_home')
ui.icon('sym_o_home')
ui.icon('sym_r_home')
ui.run()
You can use Eva icons in your app.
from nicegui import ui
ui.add_head_html('<link href="https://unpkg.com/eva-icons@1.1.3/style/eva-icons.css" rel="stylesheet" />')
ui.icon('eva-github').classes('text-5xl')
ui.run()
You can use the same approach for adding other icon sets to your app. As a rule of thumb, you reference the corresponding CSS, and it in turn references font files. This demo shows how to include Themify icons.
from nicegui import ui
ui.add_head_html('<link href="https://cdn.jsdelivr.net/themify-icons/0.1.2/css/themify-icons.css" rel="stylesheet" />')
ui.icon('ti-car').classes('text-5xl')
ui.run()
You can also use Lottie files with animations.
from nicegui import ui
ui.add_body_html('<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>')
src = 'https://assets5.lottiefiles.com/packages/lf20_MKCnqtNQvg.json'
ui.html(f'<lottie-player src="{src}" loop autoplay />').classes('w-24')
ui.run()
name: | name of the icon (snake case, e.g. add_circle) |
---|---|
size: | size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem |
color: | icon color (either a Quasar, Tailwind, or CSS color or None, default: None) |
classes
: 'Classes[Self]'
The classes of the element.
is_deleted
: 'bool'
Whether the element has been deleted.
is_ignoring_events
: 'bool'
Return whether the element is currently ignoring events.
name
: BindableProperty
props
: 'Props[Self]'
The props of the element.
style
: 'Style[Self]'
The style of the element.
visible
: BindableProperty
add_resource
(path: Union[str, Path]) -> None
Add a resource to the element.
param path: | path to the resource (e.g. folder with CSS and JavaScript files) |
---|
add_slot
(name: str, template: Optional[str] = None) -> Slot
Add a slot to the element.
NiceGUI is using the slot concept from Vue: Elements can have multiple slots, each possibly with a number of children. Most elements only have one slot, e.g. a ui.card (QCard) only has a default slot. But more complex elements like ui.table (QTable) can have more slots like "header", "body" and so on. If you nest NiceGUI elements via with ui.row(): ... you place new elements inside of the row's default slot. But if you use with table.add_slot(...): ..., you enter a different slot.
The slot stack helps NiceGUI to keep track of which slot is currently used for new elements. The parent field holds a reference to its element. Whenever an element is entered via a with expression, its default slot is automatically entered as well.
param name: | name of the slot |
---|---|
param template: | Vue template of the slot |
return: | the slot |
ancestors
(include_self: bool = False) -> Iterator[Element]
Iterate over the ancestors of the element.
param include_self: | |
---|---|
whether to include the element itself in the iteration |
bind_name
(target_object: Any, target_name: str = 'name', forward: Callable[..., Any] = [...], backward: Callable[..., Any] = [...]) -> Self
Bind the name of this element to the target object's target_name property.
The binding works both ways, from this element to the target and from the target to this element. The update happens immediately and whenever a value changes. The backward binding takes precedence for the initial synchronization.
param target_object: | |
---|---|
The object to bind to. | |
param target_name: | |
The name of the property to bind to. | |
param forward: | A function to apply to the value before applying it to the target. |
param backward: | A function to apply to the value before applying it to this element. |
bind_name_from
(target_object: Any, target_name: str = 'name', backward: Callable[..., Any] = [...]) -> Self
Bind the name of this element from the target object's target_name property.
The binding works one way only, from the target to this element. The update happens immediately and whenever a value changes.
param target_object: | |
---|---|
The object to bind from. | |
param target_name: | |
The name of the property to bind from. | |
param backward: | A function to apply to the value before applying it to this element. |
bind_name_to
(target_object: Any, target_name: str = 'name', forward: Callable[..., Any] = [...]) -> Self
Bind the name of this element to the target object's target_name property.
The binding works one way only, from this element to the target. The update happens immediately and whenever a value changes.
param target_object: | |
---|---|
The object to bind to. | |
param target_name: | |
The name of the property to bind to. | |
param forward: | A function to apply to the value before applying it to the target. |
bind_visibility
(target_object: Any, target_name: str = 'visible', forward: Callable[..., Any] = [...], backward: Callable[..., Any] = [...], value: Any = None) -> Self
Bind the visibility of this element to the target object's target_name property.
The binding works both ways, from this element to the target and from the target to this element. The update happens immediately and whenever a value changes. The backward binding takes precedence for the initial synchronization.
param target_object: | |
---|---|
The object to bind to. | |
param target_name: | |
The name of the property to bind to. | |
param forward: | A function to apply to the value before applying it to the target. |
param backward: | A function to apply to the value before applying it to this element. |
param value: | If specified, the element will be visible only when the target value is equal to this value. |
bind_visibility_from
(target_object: Any, target_name: str = 'visible', backward: Callable[..., Any] = [...], value: Any = None) -> Self
Bind the visibility of this element from the target object's target_name property.
The binding works one way only, from the target to this element. The update happens immediately and whenever a value changes.
param target_object: | |
---|---|
The object to bind from. | |
param target_name: | |
The name of the property to bind from. | |
param backward: | A function to apply to the value before applying it to this element. |
param value: | If specified, the element will be visible only when the target value is equal to this value. |
bind_visibility_to
(target_object: Any, target_name: str = 'visible', forward: Callable[..., Any] = [...]) -> Self
Bind the visibility of this element to the target object's target_name property.
The binding works one way only, from this element to the target. The update happens immediately and whenever a value changes.
param target_object: | |
---|---|
The object to bind to. | |
param target_name: | |
The name of the property to bind to. | |
param forward: | A function to apply to the value before applying it to the target. |
clear
() -> None
Remove all child elements.
default_classes
(add: Optional[str] = None, remove: Optional[str] = None, toggle: Optional[str] = None, replace: Optional[str] = None) -> type[Self]
Apply, remove, toggle, or replace default HTML classes.
This allows modifying the look of the element or its layout using Tailwind or Quasar classes.
Removing or replacing classes can be helpful if predefined classes are not desired. All elements of this class will share these HTML classes. These must be defined before element instantiation.
param add: | whitespace-delimited string of classes |
---|---|
param remove: | whitespace-delimited string of classes to remove from the element |
param toggle: | whitespace-delimited string of classes to toggle (added in version 2.7.0) |
param replace: | whitespace-delimited string of classes to use instead of existing ones |
default_props
(add: Optional[str] = None, remove: Optional[str] = None) -> type[Self]
Add or remove default props.
This allows modifying the look of the element or its layout using Quasar props. Since props are simply applied as HTML attributes, they can be used with any HTML element. All elements of this class will share these props. These must be defined before element instantiation.
Boolean properties are assumed True if no value is specified.
param add: | whitespace-delimited list of either boolean values or key=value pair to add |
---|---|
param remove: | whitespace-delimited list of property keys to remove |
default_style
(add: Optional[str] = None, remove: Optional[str] = None, replace: Optional[str] = None) -> type[Self]
Apply, remove, or replace default CSS definitions.
Removing or replacing styles can be helpful if the predefined style is not desired. All elements of this class will share these CSS definitions. These must be defined before element instantiation.
param add: | semicolon-separated list of styles to add to the element |
---|---|
param remove: | semicolon-separated list of styles to remove from the element |
param replace: | semicolon-separated list of styles to use instead of existing ones |
delete
() -> None
Delete the element and all its children.
descendants
(include_self: bool = False) -> Iterator[Element]
Iterate over the descendants of the element.
param include_self: | |
---|---|
whether to include the element itself in the iteration |
get_computed_prop
(prop_name: str, timeout: float = 1) -> AwaitableResponse
Return a computed property.
This function should be awaited so that the computed property is properly returned.
param prop_name: | |
---|---|
name of the computed prop | |
param timeout: | maximum time to wait for a response (default: 1 second) |
mark
(*markers: str) -> Self
Replace markers of the element.
Markers are used to identify elements for querying with ElementFilter which is heavily used in testing but can also be used to reduce the number of global variables or passing around dependencies.
param markers: | list of strings or single string with whitespace-delimited markers; replaces existing markers |
---|
move
(target_container: Optional[Element] = None, target_index: int = -1, target_slot: Optional[str] = None) -> None
Move the element to another container.
param target_container: | |
---|---|
container to move the element to (default: the parent container) | |
param target_index: | |
index within the target slot (default: append to the end) | |
param target_slot: | |
slot within the target container (default: default slot) |
on
(type: str, handler: Optional[events.Handler[events.GenericEventArguments]] = None, args: Union[None, Sequence[str], Sequence[Optional[Sequence[str]]]] = None, throttle: float = 0.0, leading_events: bool = True, trailing_events: bool = True, js_handler: Optional[str] = None) -> Self
Subscribe to an event.
param type: | name of the event (e.g. "click", "mousedown", or "update:model-value") |
---|---|
param handler: | callback that is called upon occurrence of the event |
param args: | arguments included in the event message sent to the event handler (default: None meaning all) |
param throttle: | minimum time (in seconds) between event occurrences (default: 0.0) |
param leading_events: | |
whether to trigger the event handler immediately upon the first event occurrence (default: True) | |
param trailing_events: | |
whether to trigger the event handler after the last event occurrence (default: True) | |
param js_handler: | |
JavaScript code that is executed upon occurrence of the event, e.g. (evt) => alert(evt) (default: None) |
remove
(element: Union[Element, int]) -> None
Remove a child element.
param element: | either the element instance or its ID |
---|
run_method
(name: str, *args: Any, timeout: float = 1) -> AwaitableResponse
Run a method on the client side.
If the function is awaited, the result of the method call is returned. Otherwise, the method is executed without waiting for a response.
param name: | name of the method |
---|---|
param args: | arguments to pass to the method |
param timeout: | maximum time to wait for a response (default: 1 second) |
set_name
(name: str) -> None
Set the name of this element.
param name: | The new name. |
---|
set_visibility
(visible: bool) -> None
Set the visibility of this element.
param visible: | Whether the element should be visible. |
---|
tooltip
(text: str) -> Self
Add a tooltip to the element.
param text: | text of the tooltip |
---|
update
() -> None
Update the element on the client side.
NameElement
TextColorElement
Element
Visibility