GUI Button Does Not Change Colour

3 visualizaciones (últimos 30 días)
Daniya Zafar
Daniya Zafar el 1 de Jun. de 2022
Respondida: Voss el 2 de Jun. de 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!

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by