psychopy.org | Reference | Downloads | Github

Image slider- Creating a slider to alter a shape of a body

Hi,

I am a MRes student working in the builder view trying to create a adaptation paradigm to images of certain BMI, which I have successfully been able to do. However at the end of this adaptation period I want to present the participant an image of a body and then the participant can then use the left arrow to decrease the body size of the image and the right arrow to increase the body size of the image and then press the space bar to enter their result when they are happy with the size of the body. I have images to work from including 60 body images from a low to a high BMI I just don’t know how I would be able to do this. I also don’t want the slider to be visible to the participant

Could you offer any help?

Thanks,

Helena

Hi Helena, you don’t need a slider to do this, as you could just directly monitor the keyboard and adjust the image accordingly.

Insert a code component on the routine. In the Each frame tab of that component’s dialog, put this code (i.e. it will run once on every screen refresh so you will get continuous control of the image size). Put the code component above the image component so that the image component gets the updated size value on every screen refresh (right click on components to change their vertical order).

key = event.getKeys()[0] # get just the last key

if key = 'left':
    # shrink the image:
    your_image_component_name.size = your_image_component_name.size - 0.01
elif  key = 'right':
    # grow the image:
    your_image_component_name.size = your_image_component_name.size + 0.01
elif key = 'space':
    # store the size in the data file and end the routine. For ease of use, we just
    # store one component of the size (i.e. the x component).
    thisExp.addData('chosen_size', your_image_component_name.size[0])
    continueRoutine = False
elif key = 'escape':
    # we need to handle this manually now for their routine:
    core.quit()

Note that the value you choose to scale the size by depends on the units of the image. Tweak it to use pixels vs normalised units etc as required.