Skip to main content

Slider

A slider provides a visual indication of adjustable content, as well as the current setting in the total range of content. Use a slider when you want people to set defined values (such as volume or brightness), or when people would benefit from instant feedback on the effect of setting changes.

Examples​

Live demo

Basic sliders​

import pglet
from pglet import Slider
with pglet.page("basic-sliders") as page:
page.add(
Slider(label='Default slider'),
Slider(label='Default disabled slider', disabled=True))

Sliders with values​

import pglet
from pglet import Slider, Button, Text
with pglet.page("sliders-with-values") as page:

def button_clicked(e):
t.value = f"Sliders values are: {s1.value}, {s2.value}, {s3.value}."
page.update()

t = Text()
s1 = Slider(width='50%', label='Slider with value', show_value=True, value=4)
s2 = Slider(width='50%', label='Slider with formatted value', show_value=True, min=0, max=100, value=40, value_format='{value}%')
s3 = Slider(width='50%', show_value=True, label='Origin from zero', min=-5, max=15, step=1, value=-2)

b = Button(text='Submit', on_click=button_clicked)
page.add(s1, s2, s3, b, t)

input()

Slider with change event​

import pglet
from pglet import Slider, Text
with pglet.page("slider-with-change-event") as page:

def slider_changed(e):
t.value = f"Slider changed to {int(s.value)}"
page.update()

t = Text()
s = Slider(width='50%', label="Slider with 'change' event", on_change=slider_changed, data=0)

page.add(s, t)

input()

Properties​

NameTypeDefaultDescription
valuenumberCurrent value of the slider.
labelstringDescription label of the slider.
minnumberThe min value of the slider.
maxnumberThe max value of the slider.
stepnumberThe difference between the two adjacent values of the slider.
showValueboolfalseWhether to show the value on the right of the slider.
valueFormatstring{value}Optional format string for the slider value, for example {value}%.
verticalboolfalseOptional flag to render the slider vertically. Defaults to rendering horizontal.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
datastringAdditional data attached to the control. The value is passed in change event data along with a slider value.

Events​

NameDescription
changeFires when the value of a slider has been changed.
focusFires when the control has received focus.
blurFires when the control has lost focus.