Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

A slider widget for OpenSesame 3.2

I've seen quite a few questions about slider widgets for OpenSesame forms. A few examples of slider widgets are floating around on this forum, but these examples aren't compatible with OpenSesame 3.2. Therefore I attached a demonstration experiment (for OpenSesame 3.2) that defines a slider widget, and shows how you can use it, both in an inline_script and in a form_base item.

I hope this is useful!

Thanked by 2eduard heliocuve

There's much bigger issues in the world, I know. But I first have to take care of the world I know.


  • Hi @sebastiaan and @eduard

    Sorry if I missed this in your code, is there a way to control for the gradations when filling the slider? I think the way it is now, it is from 0 to a 100 steps to fill in the entire slider.
    But if I wanted to have a more narrow range, say 0 to 10 with increments, or 0 to 1 in increments of 0.1 (to match the current scale), is there are way to control that directly in your code?


  • Hi Helio,

    The sliders goes from 0 to 1, but I would leave it that way, because that's easily converted to whatever range you need later on. If you want to control the gradation, you can adjust the script to, for example, round self._fill to 1 digit of precision, so that there are 10 steps (0, 0.1, 0.2, etc.).

    You can do this in SliderWidget.coroutine(), right before self._set_fill() is called. For example like so:

        def coroutine(self):
            retval = None
            while True:
                d = yield retval            
                if u'pos' not in d:
                click_x, click_y = d[u'pos']
                x, y, w, h = self.rect
                if self._orientation == u'horizontal':
                    self._fill = 1. * (click_x - x) / w
                elif self._orientation == u'vertical':
                    self._fill = 1. * (y + h - click_y) / h
                    raise ValueError(u'Invalid orientation: %s' % self._orientation)
                self._fill = round(self._fill, 1)


    Thanked by 1heliocuve

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

  • Thanks loads @sebastiaan
    works perfectly.


Sign In or Register to comment.