# How to set property of every button?

**URL:** <https://community.thunkable.com/t/how-to-set-property-of-every-button/227701>\
**Category:** Questions about Thunkable X\
**Created:** [September 15, 2019, 2:03pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701 "2019-09-15T14:03:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.thunkable.com/u/wrybread)\
**Post date:** [September 15, 2019, 2:03pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/1 "2019-09-15T14:03:53Z")

</div>

I’m making a “soundboard” app, where there’s 12 buttons and each triggers a different sound. When a button is pressed I’d like to make that button turn red, and set the color of the other buttons to blue.

I know I could do that in a “when button1.click” routine, but that’s a lot of code.

Can anyone think of a more elegant way to do that?

Is there some way to set the background color of all the buttons, and then I could set the background color of the last button pressed afterwards?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![temi.giwa](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/temi.giwa/32/40397_2.png) [@temi.giwa](https://community.thunkable.com/u/temi.giwa)\
**Post date:** [September 15, 2019, 2:33pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/2 "2019-09-15T14:33:19Z")

</div>

You can use the any button function described here: ["Any Component" Blocks - ✕ Docs](https://docs.thunkable.com/any-component-blocks#what-is-the-generic-event-block)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/f/4ff3ea0917d19e525dcdd9b903ee42ec5d4afe17.png)

---

<div class="post-metadata">

**Author:** ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.thunkable.com/u/wrybread)\
**Post date:** [September 15, 2019, 4:20pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/3 "2019-09-15T16:20:20Z")

</div>

Thanks for that. That works for making the newly clicked button red, but how to turn every other button blue?

In other words:

- I have a grid of blue buttons.

- When I press a button I want that button to turn red.

- When I press another button I want that new button to be red and all other buttons to be blue.

Any advice for turning all other buttons blue?

And is there any way to apply some logic to that action, so I can execute that action when only some buttons are clicked? (In other words, not every button should turn red when clicked)

---

<div class="post-metadata">

**Author:** ![temi.giwa](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/temi.giwa/32/40397_2.png) [@temi.giwa](https://community.thunkable.com/u/temi.giwa)\
**Post date:** [September 15, 2019, 8:21pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/4 "2019-09-15T20:21:58Z")

</div>

Hey @wrybread  
So here how I did this.

1. Create a function that takes in a variable

2. Using the “When Any Button” Dialog is clicked call that function and pass it the component

3. In the function first set all the buttons backgrounds to blue

4. Finally set the color of the the input variable to red

This worked for me in my app 🙂 The image below shows the exact blocks

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/8/4815513b940abed99ccde720c5862267c3e44593.png)

If this answered your question please don’t forget to mark my answer as the solution 😃

As a note when you create a function with an input. It shows up in the “variables” screen

---

<div class="post-metadata">

**Author:** ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.thunkable.com/u/wrybread)\
**Post date:** [September 15, 2019, 10:14pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/5 "2019-09-15T22:14:32Z")

</div>

Thanks, I’m almost there. The only thing I can’t figure out now is how to have some buttons be an exception. In other words I have a few buttons that shouldn’t change color when pressed. Can anyone think of some way to ignore the presses of a specific button?

---

<div class="post-metadata">

**Author:** ![CBVG](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cbvg/32/32401_2.png) [@CBVG](https://community.thunkable.com/u/CBVG)\
**Post date:** [September 15, 2019, 10:31pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/6 "2019-09-15T22:31:34Z")

</div>

To avoid specific buttons, would would have to name them specifically as exception. Or makes them have a very specific condition that can be identified.  
For instance, if the buttons you do not want to have changed all had their background color set to orange (for instance) then if your just be a matter of making a test “if button j get background\_color not\_equal\_to ‘orange’ do” (set to blue).

The idea is that you find a way of making them stand out so that a test can be implemented that just states “avoid this one”

---

<div class="post-metadata">

**Author:** ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.thunkable.com/u/wrybread)\
**Post date:** [September 16, 2019, 7:21am UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/7 "2019-09-16T07:21:31Z")

</div>

Thank you! Works great.

![screen2](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/e/8e7e58f33d62d8c8ea67c19cdf6522b243141aa8.jpeg)

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:08pm UTC](https://community.thunkable.com/t/how-to-set-property-of-every-button/227701/8 "2024-11-08T12:08:59Z")

</div>


