| Reference | Downloads | Github

RatingScale marker not changing after key input


I recently made a rating scale in my code but the marker always stays in the same place even when I press one of the number keys. Sometimes if I do some button mashing the marker will appear over the number I pressed, but this is not ideal. Is there a reason why my code is having this issue? The portion of my code is below; thanks for the help:

def Rating(type):
    if type == "intensity":
        text.text = "Rating #1: Please rate the intensity of the pictures just presented"
        head = "1 = None     5 = Mild     9 = Extreme"
        text.text = "Rating #2: Please rate the pleasantness of the pictures just presented"
        head = "1 = Very unpleasant   5 = None   9 = Very pleasant"
    text.pos = (0.0, 0.7)
    text.height = 0.07
    scale = visual.RatingScale(win, low=1, high=9, pos=(0,0), noMouse=True, size=1.5, markerColor='Yellow', 
        textSize = 0.7, acceptKeys = ['1','2','3','4','5','6','7','8','9'], respKeys = ['1','2','3','4','5','6','7','8','9'], 
        showAccept=False, scale = head, labels = ['1','5','9'], textColor="White")
    t0 = timer.getTime()
    while timer.getTime() < 3.0 + t0:
        if 'escape' in event.getKeys():
    rating = scale.getRating()
    RT = scale.getRT()
    if not rating:
        rating, RT = ["N/A","N/A"]
    return rating, RT 

intensity_rating, intensity_RT = Rating("intensity")
valence_rating, valence_RT = Rating("valence")

This part looks strange, and could be responsible:

acceptKeys = ['1','2','3','4','5','6','7','8','9'], respKeys = ['1','2','3','4','5','6','7','8','9'],

acceptKeys are those keys that (when pressed) mean “accept the currently selected value as the rating to save, and then don’t allow the user to keep changing their rating (= fix the marker at its position, show in gray)”. So the responseKeys should basically never be the same as the acceptKeys. (You can use singleClick=True if you want the first selection to end the rating.)

acceptKeys = ['return'], respKeys = ['1','2','3','4','5','6','7','8','9'],

Hi Jeremy,

Thank you for your response. I tried setting acceptKeys back to its default but this unfortunately did not solve the problem. I tried taking a step back and used an from the rating scale PsychoPy help page (#2):

scale = visual.RatingScale(win, low=1, high=5, markerStart=4,leftKeys='1', rightKeys = '2', acceptKeys='4')

Even when using this rating scale, pressing “1” to go left or “2” to go right doesn’t move the marker. I also turned the num lock on and off but this didn’t do anything either.

Its hard for me to know what else might be going on with your script. I suggest you make a minimal version in order to track down what is causing what. This works for me:

from psychopy import visual
win = visual.Window()
scale = visual.RatingScale(win, high=9,
    respKeys = ['1','2','3','4','5','6','7','8','9'])
for i in range(180):

In your new case, having the acceptKey also be one of the response keys could be problematic (not positive, but it looks weird).

Thanks Jeremy,

I think I actually figured out the issue I was having. I took out the escape option in my while loop, and now the marker hovers over the number I press. I’m not sure why that if statement I had in the while loop was causing that.

I suspect because by checking the keyboard using event.getKeys() on every screen refresh, you are swallowing keypresses which could otherwise be checked by the rating scale (which I think occurs during its draw method).

It might work if you use getKeys selectively to check just for the escape key, which would be something like:

if event.getKeys(['escape']):

This should leave any other keypresses in the buffer for the rating scale to check (whereas at the moment, you are clearing the buffer of all keys).