필터 지우기
필터 지우기

pushbutton uicontrol blinkiing (for click me attention seeking)

조회 수: 11 (최근 30일)
venkat ta
venkat ta 2019년 10월 22일
편집: Adam Danz 2021년 6월 12일
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