GUI带有右键菜单,带有时间显示的

1 %带有右键菜单的GUI
2 figure('Menubar','none');
3 h = uicontextmenu;
4 uimenu(h,'Label','A');
5 uimenu(h,'Label','B');
6 set(gcf,'Uicontextmenu',h);
7 
8 %获得当前时间
9 datestr(now)
右键菜单

 1 function varargout = GUI17(varargin)
 2 % GUI17 MATLAB code for GUI17.fig
 3 %      GUI17, by itself, creates a new GUI17 or raises the existing
 4 %      singleton*.
 5 %
 6 %      H = GUI17 returns the handle to a new GUI17 or the handle to
 7 %      the existing singleton*.
 8 %
 9 %      GUI17('CALLBACK',hObject,eventData,handles,...) calls the local
10 %      function named CALLBACK in GUI17.M with the given input arguments.
11 %
12 %      GUI17('Property','Value',...) creates a new GUI17 or raises the
13 %      existing singleton*.  Starting from the left, property value pairs are
14 %      applied to the GUI before GUI17_OpeningFcn gets called.  An
15 %      unrecognized property name or invalid value makes property application
16 %      stop.  All inputs are passed to GUI17_OpeningFcn via varargin.
17 %
18 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19 %      instance to run (singleton)".
20 %
21 % See also: GUIDE, GUIDATA, GUIHANDLES
22 
23 % Edit the above text to modify the response to help GUI17
24 
25 % Last Modified by GUIDE v2.5 23-Jan-2018 20:21:11
26 
27 % Begin initialization code - DO NOT EDIT
28 gui_Singleton = 1;
29 gui_State = struct('gui_Name',       mfilename, ...
30                    'gui_Singleton',  gui_Singleton, ...
31                    'gui_OpeningFcn', @GUI17_OpeningFcn, ...
32                    'gui_OutputFcn',  @GUI17_OutputFcn, ...
33                    'gui_LayoutFcn',  [] , ...
34                    'gui_Callback',   []);
35 if nargin && ischar(varargin{1})
36     gui_State.gui_Callback = str2func(varargin{1});
37 end
38 
39 if nargout
40     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41 else
42     gui_mainfcn(gui_State, varargin{:});
43 end
44 % End initialization code - DO NOT EDIT
45 
46 
47 % --- Executes just before GUI17 is made visible.
48 function GUI17_OpeningFcn(hObject, eventdata, handles, varargin)
49 % This function has no output args, see OutputFcn.
50 % hObject    handle to figure
51 % eventdata  reserved - to be defined in a future version of MATLAB
52 % handles    structure with handles and user data (see GUIDATA)
53 % varargin   command line arguments to GUI17 (see VARARGIN)
54 
55 % Choose default command line output for GUI17
56 handles.output = hObject;
57 
58 handles.ht = timer;
59 set(handles.ht, 'ExecutionMode', 'FixedRate');
60 set(handles.ht, 'Period', 1);
61 set(handles.ht, 'TimerFcn', {@dispnow,handles})
62 
63 start(handles.ht);
64 
65 % Update handles structure
66 guidata(hObject, handles);
67 
68 % UIWAIT makes GUI17 wait for user response (see UIRESUME)
69 % uiwait(handles.figure1);
70 
71 
72 % --- Outputs from this function are returned to the command line.
73 function varargout = GUI17_OutputFcn(hObject, eventdata, handles) 
74 % varargout  cell array for returning output args (see VARARGOUT);
75 % hObject    handle to figure
76 % eventdata  reserved - to be defined in a future version of MATLAB
77 % handles    structure with handles and user data (see GUIDATA)
78 
79 % Get default command line output from handles structure
80 varargout{1} = handles.output;
81 
82  
83 function dispnow(hObject , eventdata, handles)
84 set(handles.disptime, 'String', datestr(now));
带有时间显示

posted @ 2018-01-23 20:24  wydxry  阅读(412)  评论(0编辑  收藏  举报
Live2D