How to edit color of text using a conditional

If this template helps then use it. If not then just delete and start from scratch.

OS: macOS Catalina
PsychoPy version: 2020.2.5
Standard Standalone? Yes
What are you trying to achieve?:
I would like to output different color text based on a conditional. I have a csv with the variable corrAns, populated with yes and no’s. I would like to output Yes in green if the corrAns == ‘yes’ and No in red if it equals ‘no’.
What have you tried?:

clr = ‘white’
If row[corrAns] == ‘yes’:
clr = “green”
feedback = ‘YES’
clr = “red”
feedback = ‘NO’
I then input $clr in the Color box of the text component
What specifically went wrong when you tried that?:

I’ve messed around with a few variations, it sometimes says Clr isn’t defined, and i’m not sure how else to define it. Sometimes it quits without an error.


I do not really understand what you are trying to achieve. Should the colour of your feedback-text depend on the participants’ answers or should it depend on what you specified in your csv?

Best Jens

I’m guessing you’re executing this code at the end of the Routine? The problem with that is that the variable won’t exist for the first repeat, so you just need to add a start value for clr in the Begin Experiment tab