Usage Examples#
Create Various Types of Spinners#
import omni.ui as ui
from omni.kit.widget.spinner import FloatSpinner, IntSpinner, IntDragSpinner
# Create a window to hold our spinners
window = ui.Window("Spinner Examples", width=300, height=300)
with window.frame:
with ui.VStack(spacing=10, height=0):
# Label for Float Spinner
ui.Label("Float Spinner (step=0.1, range 0-10)")
# Create a FloatSpinner with specific step and range
float_spinner = FloatSpinner(step=0.1, min=0, max=10)
# Label for Int Spinner
ui.Label("Int Spinner (step=1, range 0-100)")
# Create an IntSpinner with specific step and range
int_spinner = IntSpinner(step=1, min=0, max=100)
# Label for Int Drag Spinner
ui.Label("Int Drag Spinner (step=5, range 0-50)")
# Create an IntDragSpinner with specific step and range
int_drag_spinner = IntDragSpinner(step=5, min=0, max=50)
Screenshot:#

Customize Spinner Orientation and Style#
import omni.ui as ui
from omni.kit.widget.spinner import FloatSpinner, IntSpinner
# Create a window for our custom spinners
window = ui.Window("Custom Spinner Examples", width=400, height=300)
with window.frame:
with ui.VStack(spacing=10, height=0):
ui.Label("Vertical Float Spinner (default)")
# Create a vertical float spinner (default)
vertical_spinner = FloatSpinner(step=0.5, min=0, max=10, vertical=True)
ui.Label("Horizontal Float Spinner")
# Create a horizontal float spinner
horizontal_spinner = FloatSpinner(step=0.5, min=0, max=10, vertical=False)
ui.Label("Styled Int Spinner")
# Create a spinner with custom styling
custom_style = {
"background_color": 0xFF9090FF, # Light red background
"border_color": 0x0000FFFF, # Blue border
"border_width": 1,
"border_radius": 4,
"padding": 4
}
styled_spinner = IntSpinner(step=1, min=0, max=100, style=custom_style)
Screenshot:#

Get and Set Spinner Values#
import omni.ui as ui
from omni.kit.widget.spinner import FloatSpinner, IntSpinner
# Create a window to demonstrate spinner value manipulation
window = ui.Window("Spinner Value Examples", width=400, height=300)
with window.frame:
with ui.VStack(spacing=10, height=0):
# Create a FloatSpinner with an initial value through its model
float_model = ui.SimpleFloatModel(5.5)
ui.Label("Float Spinner with model (initial value 5.5)")
float_spinner = FloatSpinner(model=float_model, step=0.1, min=0, max=10)
# Create a button to change the spinner value
with ui.HStack():
ui.Button("Set to 7.5", clicked_fn=lambda: float_model.set_value(7.5))
ui.Button("Reset to 0", clicked_fn=lambda: float_model.set_value(0))
# Create an IntSpinner with a model for value tracking
int_model = ui.SimpleIntModel(50) # Starting with a value of 50
ui.Label("Int Spinner with model (initial value 50)")
int_spinner = IntSpinner(model=int_model, step=1, min=0, max=100)
# Button to set int spinner value
with ui.HStack():
ui.Button("Set to 75", clicked_fn=lambda: int_model.set_value(75))
ui.Button("Reset to 0", clicked_fn=lambda: int_model.set_value(0))
# Widget to display current values
display_label = ui.Label("Current values:")
# Function to update displayed values using public API
def update_values():
display_label.text = f"Current values: Float = {float_model.get_value_as_float()}, Int = {int_model.get_value_as_int()}"
ui.Button("Show Current Values", clicked_fn=update_values)
Screenshot:#

Enable and Disable Spinners#
import omni.ui as ui
from omni.kit.widget.spinner import FloatSpinner, IntSpinner, IntDragSpinner
# Create a window to demonstrate enabling/disabling spinners
window = ui.Window("Enable/Disable Spinners", width=400, height=300)
with window.frame:
with ui.VStack(spacing=10, height=0):
ui.Label("Float Spinner")
float_spinner = FloatSpinner(step=0.1, min=0, max=10)
ui.Label("Int Spinner")
int_spinner = IntSpinner(step=1, min=0, max=100)
ui.Label("Int Drag Spinner")
int_drag_spinner = IntDragSpinner(step=5, min=0, max=50)
# Buttons to enable/disable spinners
with ui.HStack():
ui.Button("Enable All", clicked_fn=lambda: [
setattr(spinner, "enabled", True)
for spinner in [float_spinner, int_spinner, int_drag_spinner]
])
ui.Button("Disable All", clicked_fn=lambda: [
setattr(spinner, "enabled", False)
for spinner in [float_spinner, int_spinner, int_drag_spinner]
])
ui.Button("Toggle Float Spinner", clicked_fn=lambda:
setattr(float_spinner, "enabled", not float_spinner.enabled)
)
Screenshot:#
