Slider¶
A widget for selecting a value within a range. The range is shown as a horizontal line, and the selected value is shown as a draggable marker.






Not supported
Usage¶
A slider can either be continuous (allowing any value within the range), or discrete (allowing a fixed number of equally-spaced values). For example:
import toga
def my_callback(slider):
print(slider.value)
# Continuous slider, with an event handler.
toga.Slider(min=-5, max=10, value=7, on_change=my_callback)
# Discrete slider, accepting the values [0, 1.5, 3, 4.5, 6, 7.5].
toga.Slider(min=0, max=7.5, tick_count=6)
Reference¶
toga.Slider ¶
Slider(
id=None,
style=None,
value=None,
min=0.0,
max=1.0,
tick_count=None,
on_change=None,
on_press=None,
on_release=None,
enabled=True,
**kwargs,
)
Bases: Widget
Create a new Slider widget.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The ID for the widget.
TYPE:
|
style
|
A style object. If no style is provided, a default style will be applied to the widget.
TYPE:
|
value
|
Initial
TYPE:
|
min
|
Initial minimum value of the slider. Defaults to 0.
TYPE:
|
max
|
Initial maximum value of the slider. Defaults to 1.
TYPE:
|
tick_count
|
Initial
TYPE:
|
on_change
|
Initial
TYPE:
|
on_press
|
Initial
TYPE:
|
on_release
|
Initial
TYPE:
|
enabled
|
Whether the user can interact with the widget.
TYPE:
|
kwargs
|
Initial style properties.
DEFAULT:
|
max
property
writable
¶
max
min
property
writable
¶
min
on_change
property
writable
¶
on_change
Handler to invoke when the value of the slider is changed, either by the user or programmatically.
Setting the widget to its existing value will not call the handler.
on_press
property
writable
¶
on_press
Handler to invoke when the user presses the slider before changing it.
on_release
property
writable
¶
on_release
Handler to invoke when the user releases the slider after changing it.
tick_count
property
writable
¶
tick_count
Number of tick marks to display on the slider.
- If this is
None, the slider will be continuous. - If this is an
int, the slider will be discrete, and will have the given number of possible values, equally spaced within therange.
Setting this property to an int will round the current value to the nearest
tick.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If set to a count which is not at least 2 (for the min and max). /// note | Note On iOS, tick marks are not currently displayed, but discrete mode will otherwise work correctly. /// |
tick_step
property
¶
tick_step
Step between adjacent ticks.
- If the slider is continuous, this property returns
None - If the slider is discrete, it returns the difference in value between adjacent ticks.
This property is read-only, and depends on the values of
tick_count and range.
tick_value
property
writable
¶
tick_value
Value of the slider, measured in ticks.
- If the slider is continuous, this property returns
None. - If the slider is discrete, it returns an integer between 1 (representing
min) andtick_count(representingmax).
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If set to anything inconsistent with the rules above. |