What are you trying to achieve?:
I would like to change the Rating Scale’s marker (instead of a triangle or a circle) to an image. I have read in another post that it is better to use an image that follows the mouse position. The problem is that this would not work for my experiment because it is an MRI task and you have to use keys to move through the scale:
leftKeys='1', rightKeys = '3', acceptKeys='2'.
In the Rating Scale documentation ( RatingScale — PsychoPy v2021.2), in the marker section I have found the following:
“Can also be set to a custom marker stimulus: any object with a .draw() method and .pos will work, e.g., visual.TextStim(win, text=’’, units=‘norm’).”
Does anyone know how this code could be changed to use an image in the “custom” section of Rating scale component?
I think you will want a separate image component and then set the position of that image to be in the location of your marker. You would add a code component with this code in the each frame tab:
if slider.markerPos:
thisXpos = slider.markerPos
and this in the begin routine tab:
thisXpos = 0 # the starting X coordinate of your image/slidermarker set it a -500 or something big if you want it offscreen to start
then in the position field of your image use thisXpos, 0 and set each frame (assuming 0 is the y coordinate of your slider.
Aha sorry I also see you are using rating scale rather than slider (in general, we recommend moving towards slider, as this will eventually replace rating scale as it has greater flexibility). If you need a keyboard response perhaps use something a little more custom i.e. set the position of the image on each keypress using a code component. for example have a key response end a routine and in the end routine tab have:
maxX = 0.5
minX = -0.5
if key_resp.keys[-1] == 'right' and thisXpos < maxX:
thisXpos += 0.1
elif key_resp.keys[-1] == 'left' and thisXpos > minX:
thisXpos -= 0.1
To be honest, I’m using the rating scale component because I’m more or less new to Psychopy and I find it much more easier to change something using the “Custom” section, whereas with Slider I’m not so sure how to do it… Is it by adding a component code?
@Becca gave you some code which relies on a keyboard component (called key_resp in her code).
Your error looks like you have inserted the name of your rating scale (rating_response) instead, which doesn’t have an attribute keys because it isn’t a keyboard component.
Yes Wakefield is correct - the additional code was intended for use with a keyboard component (if that is how you want participants to change the rating! Here is a quick demo that might help - a text stimulus is placed in the position of the marker, and the user changes the rating on the slider using the left and right keyboard keys - you would just need to replace the text component with an image and use the same method for setting it’s position on each frame.
Hope this helps!
Becca
PS. note that this was made in psychopy 2021.2 sliderMarker.psyexp (15.2 KB)