Eto Slider - Showing current Value

Hi!
I’m using Eto in a Python script to get user input. I am using the slider to choose a value, but since the slider only shows ‘ticks’ it’s hard to be sure which value was chosen. I managed to show the value at the beginning, but not to update it as the slider is moved.

How could I show the current slider-value in the Eto form as the slider is being used?
Alternatively, would there be a way to show actual values instead of simple ticks?

Sounds like you just need to write an event handler have the slider “listen” to it (line 20 of the code)

import Eto.Forms as forms

def OnSliderChanged(s,e):
    global lbl
    lbl.Text = str(s.Value)

ef = forms.Form(Topmost = True)
ef.Width = 300
ef.Height = 200
layout = forms.StackLayout(
    Padding = 20,
    Orientation = forms.Orientation.Horizontal
    )
sl = forms.Slider(
    MaxValue = 20,
    MinValue = 1,
    Value = 5,
    Width = 200
    )
sl.ValueChanged += OnSliderChanged
lbl = forms.Label(Text=str(sl.Value))
layout.Items.Add(sl)
layout.Items.Add(lbl)
ef.Content = layout

ef.Show()

Thank you, that’s exactly what I was looking for!

I’m a novice and event handling, so this is new to me, very helpful, thank you for taking the time to answer me.

I wasn’t sure at first what the variables (s, e) are that OnSliderChanged needed, and why it can be run without supplying those variables. I suppose it’s specific to event handling? What do those variables represent?

I can’t speak for event handling within python itself but Eto and the rhinocommon sdk are .NET libraries
Events like Slider.ValueChanged sends a call to the handler, passing the sender object (s) and a collection of event arguments (e) into it.