GUI的问题,无法使用句柄来存储变量 [英] Problems with GUI, unable to use handles to store variables

查看:162
本文介绍了GUI的问题,无法使用句柄来存储变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个用户输入一个值的GUI,当他按下一个按钮时,它将运行一个外部函数并显示错误消息。我无法在GUI编码中成功插入变量。我很困惑,在哪里插入我的变量。我已尝试句柄,但不幸的是它不工作。

 %---在Stallfunction变为可见之前执行。 
函数Stallfunction_OpeningFcn(hObject,〜,handles,varargin)
%此函数没有输出参数,请参阅OutputFcn。
%hObject句柄图
%eventdata reserved - 在未来版本的MATLAB中定义
%处理带句柄和用户数据的结构(请参阅GUIDATA)
%varargin命令行(参见VARARGIN)
%为Stallfunction选择默认命令行输出
handles.user_entry = user_entry;
%更新句柄结构
guidata(hObject,句柄);
%UIWAIT使停顿功能等待用户响应(请参阅UIRESUME)
%uiwait(handles.figure1);

我在上面的代码中插入了变量,'user_entry'是正确的?

解决方案

user_entry 你的功能。如果通过为 user_entry 传递一个值来启动GUI:

  stallfunction(user_entry)

然后你的代码的第一行应该是:

  if〜isempty(varargin)
user_entry = varargin {1};
else
错误('请用输入值启动GUI')
结束

在此之后,您可以将 user_entry 分配给句柄结构。


I am creating a GUI where a user inputs a value and when he presses a pushbutton it runs an external function and displays error messages. I am having trouble with inserting the variable successfully in the GUI coding. I am confused as to where to insert my variable. I have tried handles but unfortunately its not working.

  % --- Executes just before Stallfunction is made visible.
  function Stallfunction_OpeningFcn(hObject, ~, 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 Stallfunction (see VARARGIN)
  % Choose default command line output for Stallfunction
   handles.user_entry = user_entry;
  % Update handles structure
  guidata(hObject, handles);
  % UIWAIT makes Stallfunction wait for user response (see UIRESUME)
  % uiwait(handles.figure1);

I have inserted the variable in the above code, which is 'user_entry' is that correct?

解决方案

user_entry is not assigned a value in your function. If you launch your GUI by passing a value for user_entry like this:

Stallfunction(user_entry)

then the first lines of your code in the openingFcn should be:

if ~isempty(varargin)
    user_entry = varargin{1};
else
    error('please start the GUI with an input value')
end

After this, you can assign user_entry to the handles structure as you're doing already.

这篇关于GUI的问题,无法使用句柄来存储变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆