pushbutton uicontrol blinkiing (for click me attention seeking)

12 次查看(过去 30 天)
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

回答(1 个)

Adam Danz
Adam Danz 2019-10-22
编辑:Adam Danz 2021-6-12
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 个评论
SUMAN DUTTA
SUMAN DUTTA 2021-6-12
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
Adam Danz 2021-6-12
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by