Matlab GUI登录界面(edit,pushbutton),键盘按下事件

(代码: 1\UI_jianpan.m)

% 登录按钮的回调函数
function login1_Callback(hObject, eventdata, handles)

name=get(handles.edit1,'String');
code=get(handles.edit2,'String');
if strcmp(name,'aa')&&strcmp(code,'bb')
    delete(gcf);   %删除(关闭)该窗体
    UI_line;   %打开另一个窗体(UI_line.m)。同目录下的另一个.m文件。
end


% 键盘按下的回调函数
function figure1_KeyPressFcn(hObject, eventdata, handles)

if double(get(gcf,'CurrentCharacter'))==13   %如果按下的是回车(13)
    login1_Callback(hObject, eventdata, handles);
end


  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matlab是一种强大的数学计算软件,它提供了GUI设计工具,可以帮助用户快速创建自己的GUI界面。下面是一个简单的Matlab GUI界面的创建步骤: 1. 打开Matlab软件,点击主界面上方的“APPS”按钮,选择“GUIDE”工具,进入GUI设计界面。 2. 在GUI设计界面,可以看到左侧有一个工具箱,其包含了各种GUI组件,如按钮、文本框、列表框等。可以通过拖拽这些组件到右侧的“GUI布局编辑器”来创建GUI界面。 3. 在“GUI布局编辑器”,可以通过调整组件的位置和大小来设计GUI界面的布局。可以通过双击组件来修改其属性,如文本框的默认文本、按钮的标签等。 4. 在设计好GUI界面后,可以通过点击“运行”按钮来预览GUI界面的效果。如果需要修改GUI界面,可以回到GUI设计界面进行修改。 5. 最后,可以通过点击“文件”菜单的“保存”按钮来保存GUI界面,保存后的GUI界面可以在Matlab直接调用和使用。 下面是一个简单的Matlab GUI界面的创建代码示例: ```matlab function varargout = mygui(varargin) % MYGUI MATLAB code for mygui.fig % MYGUI, by itself, creates a new MYGUI or raises the existing % singleton*. % % H = MYGUI returns the handle to a new MYGUI or the handle to % the existing singleton*. % % MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MYGUI.M with the given input arguments. % % MYGUI('Property','Value',...) creates a new MYGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before mygui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to mygui_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help mygui Last Modified by GUIDE v2.5 22-Jun-2021 16:08:23 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @mygui_OpeningFcn, ... 'gui_OutputFcn', @mygui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before mygui is made visible. function mygui_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to mygui (see VARARGIN) % Choose default command line output for mygui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes mygui wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = mygui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton1 msgbox('Hello World!'); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton2 set(handles.text1,'String','Button 2 Pressed!'); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton3 set(handles.text1,'String','Button 3 Pressed!'); % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton4 set(handles.text1,'String','Button 4 Pressed!'); % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton5 set(handles.text1,'String','Button 5 Pressed!'); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton6 set(handles.text1,'String','Button 6 Pressed!'); % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton7 set(handles.text1,'String','Button 7 Pressed!'); % --- Executes on button press in pushbutton8. function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton8 set(handles.text1,'String','Button 8 Pressed!'); % --- Executes on button press in pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton9 set(handles.text1,'String','Button 9 Pressed!'); % --- Executes on button press in pushbutton10. function pushbutton10_Callback(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of pushbutton10 set(handles.text1,'String','Button 10 Pressed!'); % --- Executes during object creation, after setting all properties. function text1_CreateFcn(hObject, eventdata, handles) % hObject handle to text1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值