update date and time in gui

5 次查看(过去 30 天)
Stalin Samuel
Stalin Samuel 2016-1-21
function demo1()
H.f = figure('Name','DEMO1');
set(H.f,'Units','Pixels','Position',get(0,'ScreenSize'));% adjust figure size as per the screen size
H.pb1 = uicontrol('style','push',...
'units','pixels',...
'position',[400 800 280 30],...
'fontsize',14,...
'string', datestr(now)); % datestr(now) is used to get current date and time
end
Now my intention is to update the date and time and it should be run like a real time clock

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-21
You are going to want to use a timer to update the graphics. Odd that you would put it on a pushbutton rather than as a uicontrol('style','text'), but whatever.
The timer that does the update is going to need to get the handle of the graphics object to update. It would find that easier if you returned your H out of your function, or if you had at least added a Tag to the uicontrol so that it could (inefficiently but functionally) search all the graphics objects by name. As it is now, the timer is going to have to locate the figure by name and then dig inside the figure to find the uicontrol...

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by