Changing Pushbutton BackgroundColor for 0.1 second

7 visualizaciones (últimos 30 días)
Day Hong Kim
Day Hong Kim el 22 de Abr. de 2018
Respondida: Madheswaran el 26 de Dic. de 2024 a las 6:31
I want to change BackgroundColor of pushbutton for just 0.1 second. How Can I do that?

Respuestas (1)

Madheswaran
Madheswaran el 26 de Dic. de 2024 a las 6:31
Hi Day Hong Kim,
To change the background color of a push button, you can adjust the 'BackgroundColor' property. If you intend to change the color when the button is pressed, particularly for a 'uibutton', you can utilize the 'ButtonPushedFcn' callback function.
Below is a sample code that illustrates that:
function changeButtonColor
hFig = uifigure('Name', 'Button Color Change');
hButton = uibutton(hFig, 'Text', 'Press Here', ...
'ButtonPushedFcn', @(btn,event) buttonCallback(btn));
function buttonCallback(btn)
btn.BackgroundColor = [1, 0, 0]; % Change to red
pause(0.1); % Pause for 0.1 seconds
btn.BackgroundColor = [0.94, 0.94, 0.94]; % Revert to default color
end
end
For more details, refer to the following MathWorks docmentation:
  1. uibutton - https://mathworks.com/help/matlab/ref/uibutton.html
  2. Creating callback functions - https://mathworks.com/help/matlab/creating_guis/write-callbacks-for-apps-created-programmatically.html
Hope this helps!

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by