Slider¶

A horizontal track with a draggable thumb for selecting a numeric value within a range. The slider supports continuous values or discrete steps when a step increment is specified.
Constructor¶
nib.Slider(
value=0,
min_value=0,
max_value=1,
step=None,
label="",
on_change=None,
tint=None,
disabled=False,
**modifiers,
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
float |
0 |
Initial value of the slider. Must be between min_value and max_value. |
min_value |
float |
0 |
Minimum value of the range. |
max_value |
float |
1 |
Maximum value of the range. |
step |
float |
None |
Step increment for discrete values. When set, the slider snaps to multiples of this value. When None, values are continuous. |
label |
str |
"" |
Optional text label displayed with the slider. |
on_change |
Callable[[float], None] |
None |
Callback called continuously as the slider value changes. Receives the new float value. |
tint |
Color | str |
None |
Tint color for the filled portion of the slider track. Accepts a Color enum, hex string, or RGB tuple. |
disabled |
bool |
False |
Whether the slider is disabled and non-interactive. |
**modifiers |
Common view modifiers: padding, background, opacity, width, etc. |
Examples¶
Volume control¶

import nib
def main(app: nib.App):
app.title = "Volume"
app.icon = nib.SFSymbol("speaker.wave.2")
app.width = 360
level = nib.Text("50%", font=nib.Font.HEADLINE, width=50)
def on_volume(value):
level.content = f"{int(value)}%"
app.build(
nib.VStack(
controls=[
nib.Text("Output volume", font=nib.Font.HEADLINE),
nib.HStack(
controls=[
nib.SFSymbol("speaker.wave.1.fill"),
nib.Slider(
value=50,
min_value=0,
max_value=100,
on_change=on_volume,
tint=nib.Color.BLUE,
width=200,
),
nib.SFSymbol("speaker.wave.3.fill"),
level,
],
spacing=8,
),
],
spacing=10,
padding=20,
)
)
nib.run(main)
Rating slider with discrete steps¶

import nib
def main(app: nib.App):
app.title = "Rate"
app.icon = nib.SFSymbol("star")
stars = nib.Text("★★★☆☆", font=nib.Font.TITLE2, foreground_color=nib.Color.YELLOW)
def on_rating(value):
stars.content = "★" * int(value) + "☆" * (5 - int(value))
app.build(
nib.VStack(
controls=[
nib.Text("How was your experience?", font=nib.Font.HEADLINE),
stars,
nib.Slider(
value=3,
min_value=1,
max_value=5,
step=1,
on_change=on_rating,
tint=nib.Color.YELLOW,
width=220,
),
],
spacing=10,
padding=20,
)
)
nib.run(main)