# Images as buttons on the screen

**URL:** <https://discourse.psychopy.org/t/images-as-buttons-on-the-screen/18816>\
**Category:** Builder\
**Created:** [December 9, 2020, 12:35am UTC](https://discourse.psychopy.org/t/images-as-buttons-on-the-screen/18816 "2020-12-09T00:35:30Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [December 9, 2020, 10:06pm UTC](https://discourse.psychopy.org/t/images-as-buttons-on-the-screen/18816/9 "2020-12-09T22:06:56Z")

</div>

I’m suggesting you don’t need to do any of this stuff:

> [@Antonio\_Neto](#):
>
> ```auto
> #figure out which button they pressed
> if mouse_resp_RM.isPressedIn(button1) : #button1 is the name of your first circle shape
> theirResponse = 1
> elif mouse_resp_RM.isPressedIn(button2) : 
> theirResponse = 2
> elif mouse_resp_RM.isPressedIn(button3) : 
> theirResponse = 3
> elif mouse_resp_RM.isPressedIn(button4) : 
> theirResponse = 4
> 
> ```

The mouse component will automatically store for you what stimulus name was clicked (because you have told it to do exactly that by providing the list of clickable stimuli).

So in the “end routine” tab, you just need code that does something like this:

```auto
if RESPOSTARMexemplo is in mouse_resp_RM.clicked_name:
    accuracy = 1
else:
    accuracy = 0

thisExp.addData("theirResponse", mouse_resp_RM.clicked_name[0])
thisExp.addData("accuracy", accuracy)

```

Note that the clicked name will correspond to the names of the stimuli, like `'button1'`, `'button2'`, etc. So either the variable you use to compare against has to look like that, or you need to extract just the last character of the clicked name (i.e. just the number) to compare against. If so, you need to be careful about the types of your variables. The integer value `1` won’t equal the character `'1'`, for example, so you might have to coerce one or the other using `str()` or `int()` to make the comparisons work.

---

_[View the full topic](https://discourse.psychopy.org/t/images-as-buttons-on-the-screen/18816)._
