Psychopy scale and labels

(Psychopy Coder v.2022.2.4)
In an experiment i would like to create a scale to rate the confidence of the participant, with two labels, the left one being ‘uncertain’ and the right one ‘certain’. The scale is 1-100 but the numbers are not shown. I would like uncertain to be written in red, and certain in green. So far i could only change both labels to the same color, but not one for each.
I came to this :
label_1 = visual.TextStim(win, text=‘uncertain’, height=0.5, color=‘red’, colorSpace=‘rgb’)
label_2 = visual.TextStim(win, text=‘certain’, height=0.5, color=‘green’, colorSpace=‘rgb’)

rating_scale = visual.RatingScale(win=win, name=‘rating_scale’, marker=‘circle’,
size=1.5, pos=[0.0, -0.3], low=0, high=100, labels=[label_1, label_2], scale=‘’, showValue=False,
acceptPreText=“OK”, acceptText=“OK”)
But when i run it, the labels are super weird, it says something like TextStim(class=<class etc.
Does anybody know how I could make this work please ?
Thanks, have a nice day!

Try labels=[“uncertain”,“certain”] instead of labels=[label_1, label_2]

Thank you for your answer, unfortunately i get this error : NameError: name ‘uncertain’ is not defined :confused:

Did you put apostrophes around the labels as wakecarter did?
Also, try labels=[label_1.text, label_2.text]

1 Like

ah i forgot the apostrophes ahaha, so the two solutions work to make the labels appear but they are still written in light grey, and i would like them to be red for the uncertain and green for the certain.
Thank you for the help!

It could be helpful if you showed us the full code. I don’t fully understand the issue.

What about something like that?

labels = [label_1, label_2]

for label in labels:
    label.color = 'red' if label.text == 'certain' else label.color = 'green'

# Or, without a ternary operator
for label in labels:
    if label.text == 'certain':
        label.color = 'red'
        label.color = 'green'

Hi, so the full code is 1800 lines, but here is the full part

Initialize components for Routine “rating” —

confidence = visual.TextStim(win=win, name=‘confidence’,
font=‘Open Sans’,
pos=(0,0.3), height=0.05, wrapWidth=None, ori=0.0,
color=‘white’, colorSpace=‘rgb’, opacity=None,

label_1 = visual.TextStim(win, text=‘uncertain’, height=0.5)
label_2 = visual.TextStim(win, text=‘certain’, height=0.5)
labels = [label_1, label_2]

rating_scale = visual.RatingScale(win=win, name=‘rating_scale’, marker=‘circle’,
size=1.5, pos=[0.0, -0.3], low=0, high=100, labels=[label_1.text, label_2.text], scale=‘’, showValue=False,
acceptPreText=“OK”, acceptText=“OK”)

I tried putting this part before and after the rating scale and it just doesn’t work.
for label in labels:
if label.text == ‘certain’:
label.color = ‘red’
label.color = ‘green’
I’m very new to this but basically with labels = [label_1.text,label_2.text] the scale appears, the labels too, in the right place, but both in light grey, and i would like to change the font color, in red for uncertain and green for certain. I don’t know if it’s clearer

This is how its looking with this code :

This code seems to be working fine:

Any reason you use instead of ' or "? I get syntax error:

if label.text == ’certain’:
SyntaxError: invalid character in identifier

If you could attach a simplistic version of the experiment, with the specific issue, it would be easier to help you.

# --- Import packages ---
from psychopy import visual, event, core

# --- Setup the Window ---
win = visual.Window(size=[1707, 1067], fullscr=True, screen=0, 
                    winType='pyglet', allowStencil=False,
                    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
                    blendMode='avg', useFBO=True, units='height')
win.mouseVisible = True

# create rating scale and labels
rating_scale = visual.RatingScale(win=win, name='rating_scale', marker='circle',
                                  size=1.5, pos=[0.0, -0.3], low=0, high=100,
                                  scale=' ', showValue=False, acceptPreText="OK",
                                  acceptText="OK", textColor = [0, 0, 0])

label_1 = visual.TextStim(win, text="uncertain", height=0.05, color="red", pos=[-0.4, -0.2])
label_2 = visual.TextStim(win, text="certain", height=0.05, color="green", pos=[0.4, -0.2])

rating_scale.labels = [label_1, label_2]

# draw labels and wait for response
while rating_scale.noResponse:                 
    for label in rating_scale.labels:

# print response and reaction time

# close window

found the solution!!! 
Thanks to all ;)
1 Like