How to change the feedback text colour if the effect words were set in a code component?

I use PsychoPy 2020.2.6 on Windows 10.

During the acquisition phase of a learning experiment, induction paradigm, I want that the effect words, which appear after the participant has pressed a certain key, keep their white colour (as it is now,) but that the “too slow!” - feedback, that appears if they take longer than 1000ms to respond, is shown in red colour.

My problem is that I have not set the effects, which appear after each key press, by using an .xlsx file, but I have set them in a code component as followed:

if (group is ‘category’ and condition is ‘congruent’ and input_phase.keys is ‘left’):
resp = ‘furniture’

elif (group is ‘category’ and condition is ‘congruent’ and input_phase.keys is ‘right’):
resp = ‘animal’

else:
resp = “too slow!”

Now, I cannot change only the “too slow” message into red colour.

What did you try to make it work?:

I tried various options using another code fragment, and none of it worked. The last one was this:

if resp is ‘furniture’ or ‘chair’ or ‘cat’ or ‘animal’ and effect_txt.color == “white”:
effect_txt.color = “white”
else:
effect_txt.color = ‘red’

What specifically went wrong when you tried that?:

What goes wrong in this case is that all effects are ahown in white again. Before, I also tried to outline all options that should be shown in white with an if…else function, but it happened the same. If I use the response latency in the if…else function, I get everything in red.

Does somebody maybe know how to change this? Or do I have to change my whole experiment using .xlsx files instead of the code components?

Thank you for any thought and answer on this!

I do a very similar thing. Edit your first code in ‘each frame’ to:

if (group is ‘category’ and condition is ‘congruent’ and input_phase.keys is ‘left’):
    resp = ‘furniture’
    respColor = 'white'

elif (group is ‘category’ and condition is ‘congruent’ and input_phase.keys is ‘right’):
    resp = ‘animal’
    respColor = 'white'

else:
    resp = “too slow!”
    respColor = 'red'

Then in the text component where you show the word, put $respColor in the ‘color’ box and $resp in the text box. And make sure to set the dropdown menus to ‘each frame’ for both.

Hello Sal,

thank you very much for your reply! I added the changes and now it works perfectly :slight_smile:

Whilst applying the code I realized that it is also important not to forget to set the colour in the stimulus window to “set every repeat”.