# Change opacity of the shape to reveal the text on mouse click

**URL:** https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431
**Category:** Builder
**Created:** [October 19, 2022, 8:19am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431 "2022-10-19T08:19:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Dasha\_Mesquita](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dasha_mesquita/32/35795_2.png) [@Dasha\_Mesquita](https://discourse.psychopy.org/u/Dasha_Mesquita)
#### Post date: [October 19, 2022, 8:19am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/1 "2022-10-19T08:19:44Z")

</div>

I need to reveal the text under an image with a mouse click. What are the steps to change the opacity of the shape on click that covers the text in Builder (or in Code, though I am a novice)?

\*\*OS Win11  
\*\*PsychoPy version 2022.2.4

---

<div class="post-metadata">

### Author: ![ajus](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@ajus](https://discourse.psychopy.org/u/ajus)
#### Post date: [October 19, 2022, 10:06am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/2 "2022-10-19T10:06:57Z")

</div>

Hi @Dasha_Mesquita,

if you have an image component `image_stim` and a mouse component `mouse`, you can add a code component to your routine and have

**Each frame**

```auto
if mouse.isPressedIn(image_stim):
    image_stim.opacity = 0

```

---

<div class="post-metadata">

### Author: ![Dasha\_Mesquita](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dasha_mesquita/32/35795_2.png) [@Dasha\_Mesquita](https://discourse.psychopy.org/u/Dasha_Mesquita)
#### Post date: [October 21, 2022, 11:04am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/3 "2022-10-21T11:04:04Z")

</div>

@ajus, I did what you suggested and had this error. Do you have any idea what it means and what to do with this?

Traceback (most recent call last):  
File “C:\Users\dasha\Documents\PsychoPy\_TESTS\_for PhD\LLAMA\untitled\_LLAMA\_B\_lastrun.py”, line 116, in   
trials\_LLAMA\_B = data.TrialHandler(nReps=None, method=‘random’,  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 147, in **init**  
self.nReps = int(nReps)  
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’  
################# Experiment ended with exit code 1 [pid:3864] #################  
709.4300 EXP Imported C:/Users/dasha/Documents/PsychoPy\_TESTS\_for PhD/LLAMA/Llama\_B\_test.xlsx as conditions, 20 conditions, 3 params  
709.4327 INFO Loaded monitor calibration from [‘2022\_10\_17 10:29’]

---

<div class="post-metadata">

### Author: ![ajus](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@ajus](https://discourse.psychopy.org/u/ajus)
#### Post date: [October 21, 2022, 11:52am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/4 "2022-10-21T11:52:34Z")

</div>

This seems to have nothing to do with the code. In your loop “trials\_LLAMA\_B” the nReps field seems to be empty. It must contain the number of repetitions you need.

---

<div class="post-metadata">

### Author: ![Dasha\_Mesquita](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dasha_mesquita/32/35795_2.png) [@Dasha\_Mesquita](https://discourse.psychopy.org/u/Dasha_Mesquita)
#### Post date: [October 24, 2022, 6:19am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/5 "2022-10-24T06:19:14Z")

</div>

Thank you so much! I fixed it and everything is working!)) I was wondering if you could help me with another question. I tried to find the solution online but I am not even sure how to formulate my question)  
I want people to click, see a word for several seconds, then the word disappears, and to see it again a person needs to click once more.

I forgot to add, that I need to have several clickable images on the screen. (maybe that is important)

---

<div class="post-metadata">

### Author: ![ajus](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@ajus](https://discourse.psychopy.org/u/ajus)
#### Post date: [October 24, 2022, 8:27am UTC](https://discourse.psychopy.org/t/change-opacity-of-the-shape-to-reveal-the-text-on-mouse-click/31431/6 "2022-10-24T08:27:30Z")

</div>

So the timeline would be: I click an image, and it disappears to reveal a text. After some time (how long?) the text disappears, I click again (where?), and the text reappears. Right?

How should it work with different images? Can I click all images? Or just one? Do they all do the same thing independently from another?
