How can i change the colour of text stimuli

Hi,How can i change the colour to red when 2 seconds left in duration time when I present a text stimuli for 10 seconds with white colour. Can anyone help please? Thanks very much.

1 Like

Hi @a544746760, you could add the following to a code component, ā€œEach Frameā€ tab:

if t >=8 and text.color == "white":
    text.color = "red"

This will set the text component color (text component is called text) to red after 8 seconds, and only if the text is white, therefore not setting the color more than once.

Hi, @dvbridges, thank you very much for helping me! Also, I have another question. T(8 seconds in this case ) is defined as how long the text component has been presented, however, how to dedine the duration time(10 seconds in this case) of text component. I have tried ā€˜durationā€™ and ā€˜duration timeā€™ , however, it does not work.

1 Like

Oh, do you mean that the text component does not start at time zero of each trial, but later in the trial?

The text component starts at time zero. The main purpose of changing the color of text component is to remind the participants that time is running out when remaining duration time is only 2 seconds.
So I have tried:
if (duration-t) <=2 and text.color == ā€œwhiteā€:
text.color = ā€œredā€
however, it does not work.Different trials have different duration time,so i want to know how to dedine the duration time of text component.
Thanks again!

I see, so how are you defining the length of each trial?

I do not konw how to define the length of each trial. I tried ā€˜durationā€™ and ā€˜durationTimeā€™, however, it is does not work.

Hello, Many thanks for the code. But mine is not working. I want to change the color of my text (from darkgreen to darkred) after 3 secs (of total duration of 10sec). When I put the code in the ā€œEach Frameā€ tab of the code component, the colour (darkgreen) remained the same. Please help me with your advice.

Please could you show your code?

1 Like