psychopy.org | Reference | Downloads | Github

Changing Number of Slider Options


#1

OS (e.g. Win10): Mac OSX 10.13
PsychoPy version (e.g. 1.84.x): 3.0.6
Standard Standalone? (y/n) y
What are you trying to achieve?: I’d like to use PsychoPy to administer a survey where the number of options changes on different “pages” (i.e., iterations of a loop). When I do this using slider objects to collect responses, the marker positions allowed do change, but the lines/circles indicating these positions do not.

What did you try to make it work?:
I added a bit of code that runs at the start of the routine:

# nResps = number of responses on this iteration
# allSliders = a list of all the slider objects on screen
for j,slider in enumerate(allSliders):
    slider.ticks = np.arange(nResps)+1
    slider.tickLines.xys = slider.tickLocs

What specifically went wrong when you tried that?:
The marker positions allowed do change, but the lines/circles indicating these positions do not.


#2

Hi, I think it would be easier to just recreate a slider object on every trial, with the settings you want. However, if you wanted, you could update the slider object after changing its attributes by recreating the elements used for the Slider object. You do this by calling the _createElements method:

for j,slider in enumerate(allSliders):
    slider.labels.append('one')  # Append any label you want, or remove one
    slider.ticks = np.arange(nResps)+1
    slider.tickLines.xys = slider.tickLocs
    slider.tickLocs = None
    slider.labelLocs = None
    slider._createElements()

#3

Thank you @dvbridges! For the curious, here’s how I implemented the same change in javascript for our online experiment:

for (i=0; i<allSliders.length; i++) {
    allSliders[i].ticks = ticks;
    allSliders[i]._needVertexUpdate = true;
    allSliders[i]._buildSlider();
}