| Reference | Downloads | Github

Stop showing the text stimulus

Hello everyone,
I am a PsychoPy & Python newbie.I am making an experiment where participants answer several questions. Before they will enter their answers, I’d like participants to have the option (but not the requirement) of getting another participant’s answer (called “advice”). In other words, if participants choose to get the answer, the answer will be shown on the screen. If not, the answer will not be presented.

To the end, I created a text component (named by “AdviceSelection”) in the builder and then set the opacity = 0 (constant). Next, I put the code component that if the participant enter “y” key, the opacity of the AdviceSelection text component will change 1 after 2 seconds.
The problem that I face is that the AdviceSelection text stimulus already shown is still shown after the routine. What I mean is that the text stimulus do not disappear at the next routine. You can see how it is messy in the attached file.

I want to know how to reset the opacity of the AdviceSelection text stimulus 0 again at the end of the routine (before moving to the next routine). I tried to put some codes indicating that if the participants entered their answer, the exact same text stimulus but white color will be presented at the same location. I thought it would cover up the already-shown text stimulus because the background color is white. But it does not cover up perfectly. I read through all of the discussions with regard to “opacity” on this website. I cannot solve this issue because of my lack of programming knowledge.

I wrote down my codes below and attached the psycopi file.

PsycoPI.psyexp (15 KB)

(The following code is written in the Each Frame. The code component in the Builder is located just above the text component called “AdviceSelection.”)

if event.getKeys('y'): # if y key pushed,
   import time
   thisExp.addData('Adviceseeking', 'yes')
   AdviceSelection = visual.TextStim(win=win, name='AdviceSelection',
   text=u'The estimate of advisor # 34 is: 75',
   pos=(0, 0.0), height=0.06, wrapWidth=None, ori=0, 
   color=u'Black', colorSpace='rgb', opacity=1,

It is unclear from your description vs the tag you are using whether you are using Builder rather than coding your own experiment, but I suspect the former.

When it comes to setting the opacity during the routine, you can’t use the time.sleep() function in Builder code. Builder is inherently structured on drawing to the screen on every screen refresh. If you insert a 2 second pause, you will break all of the timing for everything else.

So you need to do something like the code below, to keep track as to what the time is during the routine. t is a Builder variable that tells you the current routine time:

Begin routine tab:

advice_sought = False
text_visible = False
your_text_component_name.opacity = 0 # should always be invisible at start of trial

Every frame tab:

# only check for a keypress if a response hasn't already been made:
if not advice_sought and event.getKeys('y'):
    on_time = t + 2.0 # when to show the text (2 s from now)
    thisExp.addData('Adviceseeking', 'yes')
    advice_sought = True # so we don't check again

if not text_visible and t > on_time: # 2 s after the response was made
    your_text_component_name.opacity = 1 # show the text
    text_visible = True # so we don't need to keep setting this