pushbutton uicontrol blinkiing (for click me attention seeking)
14 views (last 30 days)
Show older comments
Hi,
I am looking the set function for clicking the pushbutton with some highlights , its for special attention.
That would be really appriciated if some body send the idea.
Thanks
Best regards
Venkat
0 Comments
Answers (1)
Adam Danz
on 22 Oct 2019
Edited: Adam Danz
on 12 Jun 2021
Here's a functional demo you can apply to your GUI (whether it's built from Guide, uicontrol, or App Designer). Save it to an m file and run it.
It creates a timer that iteratively turns on/off the visibility of a graphics object. You could change the background color or any other property instead. When the timer is stopped, the stopFcn ensures that the botton is returned to its original state.
See in-line comments for more detail.
% Create a figure that contains a button.
% In this demo, the button does nothing.
figure()
bh = uicontrol('style','PushButton','String','press me');
% Create timer class
% This can be created in the startup function where you have access
% to the button's object handle.
t = timer();
t.TimerFcn = {@flashButtonTimer, bh}; % This function responds to start(t)
t.StopFcn = {@stopButtonFlash, bh}; % This function responds to stop(t)
t.Period = 0.25; % delay between flashes (seconds)
t.ExecutionMode = 'fixedSpacing';
TasksToExecute = 3;
% Define function that controlls the button flashes after start(t) is executed
% This can go anywhere in your GUI code.
function flashButtonTimer(~, ~, objHand)
% objHand is the handle to the button that should flash
% Toggle the visibility of the object. Note, you coud do lots of other things
% instead such as changing the background color of the object.
if strcmpi(objHand.Visible,'on')
objHand.Visible = 'off';
else
objHand.Visible = 'on';
end
end
% Define the stop function that ensures the button visibility is on at the end.
% This can also go anywhere in your GUI code.
function stopButtonFlash(~,~,objHand)
objHand.Visible = 'on';
end
To start flashing the button, use start(t) and to stop, stop(t). These should be called from within your GUI and the callback function must have access to 't', the timer.
When you close the gui, you should delete the timer using delete(t).
2 Comments
SUMAN DUTTA
on 12 Jun 2021
How to highlight a pushbutton already coded in a gui by changing it's colour i.e. making it blink by different colours in the middle of the execution of the program.
Adam Danz
on 12 Jun 2021
You can adapt the example in my answer or this example using a lamp to apply it to your button. You can change the BackgroundColor property, for example.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!