psychopy.org | Reference | Downloads | Github

Can't get slider component or code to function

I have a nearly finished experiment but am trying to add a visual analogue scale (i.e., a slider) as a last routine. However, I can’t get anything to work from the code I find online.

In brief, participants make a choice, a short video plays, and then I want the VAS screen to display. Here is the code for the video playing:

PRP_Clock.reset()
thisExp.addData("OutStart", time.strftime('%x %X'))

Movie.setAutoDraw(True)
Movie.play()
Choice_Window.flip()

while Movie.status != constants.FINISHED:
    Choice_Window.flip()
    if Movie.getCurrentFrameTime() >= (Movie.duration - 0.1):
        Movie.pause()
Movie.setAutoDraw(False)
event.waitKeys(keyList=["space"])

Once the spacebar is pressed, I’m wanting it to move on to a routine with the slider. My code doesnt work as it advances to a blank screen. I’m trying:

VAS = visual.Slider(win=win, name='VAS',
    pos=(0, -0.4), units=None,
    labels=("Very Unhappy","Neutral","Very Happy"), ticks=(0,25,50,75,100), granularity=1.0,
    style='slider', styleTweaks=(), opacity=1.0,
    color='LightGray', fillColor='Red', borderColor='White', colorSpace='rgb',
    font='Arial', labelHeight=0.05,
    flip=False, depth=0, readOnly=False)
VAS.markerPos = 50

VAS.draw()
Choice_Window.flip()

while not VAS.rating:
    VAS.draw()
    Choice_Window.flip()
    if VAS.getRating() is not None and VAS.status == STARTED:
        continueRoutine = False

I’ve also tried putting in a slider component within the builder, but doing so causes the experiment to freeze after the movie and it won’t advance. I don’t feel like this should be hard, but I need some help figuring out what I"m missing. Alternatively, if someone wouldn’t mind sharing their code for a slider in full that would be much appreciated.

At first glance I’d guess it’s because your while loop is halting execution, so clicks on the slider aren’t registered and .rating remains None. Adding via Builder is definitely the preferred method and should work, what version are you using?

I am using the most current version I believe, 2021.2.

And yes, I also wanted to use the builder and don’t understand why it won’t execute. Here are some screenshots.
image
image
image

Basically, if I don’t have the SWB routine at all, my loop will execute fine and rerun. However, with the VAS2 slider component in the SWB routine, the video refuses to advance to the SWB routine and the experiment stalls.

I’ve found the solution. It turns out that because I was using a window other than Psychopy’s default name for a window, “win,” that the slider simply wasn’t displaying. Once I changed all my code to use a window name consistent with Psychopy’s default (i.e., window=win), the slider displayed appropriately.

1 Like