GUI Button Does Not Change Colour

1 Ansicht (letzte 30 Tage)
Daniya Zafar
Daniya Zafar am 1 Jun. 2022
Beantwortet: Voss am 2 Jun. 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!

Akzeptierte Antwort

Voss
Voss am 2 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by