How to only show image when button is pushed?

11 views (last 30 days)
Hello all, I am trying to display several images in AppDesigner, depending on what button is pushed (both buttons should be able to be pushed at the same time).
I have two state button 'app.Button' and 'app.Button2'. I also have an Image 'app.Image'.
When 'Button' is pushed, I want 'pepper.png' to appear, and when 'Button2' is pushed, I want 'cucumber.png' to appear. For those purposes, I have created the following callbacks:
function ButtonValueChanged(app, event)
value = app.Button.Value;
app.Image.ImageSource = 'pepper.png';
function Button2ValueChanged(app, event)
value = app.Button2.Value;
app.Image.ImageSource = 'cucumber.png';
So far, this code works.
Now, I want the image 'pepper&cucumber.png' to appear if both Buttons are pushed.
Additionnally, if I deselect 'Button', I want 'pepper.png' to disappear (which is currently not the case, it just stays).
Thanks in advance for all your advice!
elevonm on 28 Jul 2021
Edited: Rik on 28 Jul 2021
Thank you both for the help!

Sign in to comment.

Accepted Answer

elevonm on 28 Jul 2021
Edited: Rik on 28 Jul 2021
Ok this helped a lot, thank you! I defined a function in the methods that contains all the above if statements, and then I called this function in my callbacks.
Thank you so much!!

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!