# Displaying stimulus for a limited amount of time before disappearing

**URL:** <https://discourse.psychopy.org/t/displaying-stimulus-for-a-limited-amount-of-time-before-disappearing/19739>\
**Category:** Builder\
**Created:** [January 19, 2021, 10:38am UTC](https://discourse.psychopy.org/t/displaying-stimulus-for-a-limited-amount-of-time-before-disappearing/19739 "2021-01-19T10:38:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tandy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tandy/32/9246_2.png) [@tandy](https://discourse.psychopy.org/u/tandy)\
**Post date:** [January 19, 2021, 4:26pm UTC](https://discourse.psychopy.org/t/displaying-stimulus-for-a-limited-amount-of-time-before-disappearing/19739/2 "2021-01-19T16:26:42Z")

</div>

I think is not changing back because the code checks the timer well before 0.5 seconds has elapsed. Try this way:

```auto
#in the begin routine tab

opacClock = core.Clock()

# in the each frame tab
if key_resp.keys:
    opacClock.reset() #resets the clock back to 0
    if key_resp.keys == 'a':
        opacleft =1
        opacright=0
    elif key_resp.keys == 'p':
        opacright = 1
        opacleft=0

if opacClock.getTime() >= 0.5: #after 0.5 seconds
   opacleft =0
   opacright =0 #both opacity are set to 0

```

For the JS conversion look at this: [PsychoPy Python to Javascript crib sheet](https://discourse.psychopy.org/t/psychopy-python-to-javascript-crib-sheet/14601)

Also, changing the opacity online seems to cause a lot of problem, so if you can try changing the color instead (if you make the fillcolor = to the background color the stimulus disappear), and if you can’t try searching the forum for a solution.

tandy

---

_[View the full topic](https://discourse.psychopy.org/t/displaying-stimulus-for-a-limited-amount-of-time-before-disappearing/19739)._
