app designer button push color change
Show older comments
Hi everyone,
I have an app designer app that includes a button that turns green when pressed. However, whenever any other button is pressed, a panel comes up but does not cover the now green button. So, the button is still green but I want it to go back to white when any other button is pressed after.
Thank you!!
1 Comment
Caglar
on 9 Nov 2018
You can create a method (function) that sets that button's color to original color and call that function in each of other buttons.
Accepted Answer
More Answers (1)
Prince Ogbodum
on 1 Sep 2020
0 votes
Is there a way to get this done for MATLAB R2007b?? I mean to change background color only when another buton is pressed. For example: I have an app with 3 pushbuttons and I want a case whereby If Psbtn1 is pressed its color turns red to show it is active, if Psbtn2 is then pressed it turns red while Psbtn1 returns to its default color to show that the active state is that of Psbtn2
3 Comments
Cris LaPierre
on 1 Sep 2020
Edited: Cris LaPierre
on 1 Sep 2020
In 2007b, I suspect you are using GUIDE instead of App Designer. Look at the properties of your pushbutton to find the name of the background color property. You can then access these through the handles structure.
For example, if I have two pushbuttons in my gui (pushbutton1 and pushbutton2), and I want pushbutton1 to turn red when I click pushbutton2, I would add the following line of code to pushbutton2_Callback
handles.pushbutton1.BackgroundColor = 'r';
Prince Ogbodum
on 1 Sep 2020
Thanks for the response Cris. However, that didn't seem to solve my problem. I have attached a screen short of the response I got after inputing the code and clicking the pushbutton. Let me restate my question for better clarity.
I am trying to create a GUI to control the speed and rotation of a DC motor. So, I want a case whereby if the pushbutton representing speed1 is pressed (there are 5 of them), it turns red to indicate to the user or observer that the motor is running at speed1. If the pushbutton representing speed2 is pressed then it turns red while speed1 button returns to its default color to indicate that the motor is now running at speed2 and so on. So, what I need is the code to achieve this. Thanks in anticipa
tion.
tion.
Steven Lord
on 1 Sep 2020
In release R2007b, you can't use the dot syntax to set properties of a Handle Graphics object. You will need to call set.
set(handles.pushbutton2, 'BackgroundColor', 'r')
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!