GUI Button Does Not Change Colour

1 vue (au cours des 30 derniers jours)
Daniya Zafar
Daniya Zafar le 1 Juin 2022
Réponse apportée : Voss le 2 Juin 2022
Hi there,
I created a simple GUI using appdesginer.
As soon as I press the start button, it should change to stop, execute the code block and then change back to start. My function looks like this:
function StartButtonPushed(app, event)
tic
app.StartButton.BackgroundColor = [0.95 0.28 0.28]; % red
app.StartButton.Text = 'STOP';
% bunch of code
app.StartButton.BackgroundColor = [0.96 0.96 0.96]; % default grey
app.StartButton.Text = 'Start';
toc
end
tic/toc returns:
>> Elapsed time is 5.617925 seconds.
My button doesn't change the colour or text when Start is pressed. If I put a breakpoint in my code block, I do see the text and colour change to stop and red respectively.
Is 5s not enough gap for the button to change or am I doing somthing wrong?
Thanks for the help!

Réponse acceptée

Voss
Voss le 2 Juin 2022
Insert drawnow commands immediately after changing the Color/Text, in order to see the changes right away:
function StartButtonPushed(app, event)
tic
app.StartButton.BackgroundColor = [0.95 0.28 0.28]; % red
app.StartButton.Text = 'STOP';
drawnow();
% bunch of code
app.StartButton.BackgroundColor = [0.96 0.96 0.96]; % default grey
app.StartButton.Text = 'Start';
drawnow();
toc
end

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by