在subgui中单击关闭按钮后,在maingui中显示按钮

时间:2016-12-10 16:54:51

标签: matlab user-interface matlab-figure

我有一个带有2个按钮的主gui。第一个按钮打开一个subgui,另一个按钮是" run"按钮是'Enable'=Off。它是灰色的,不可点击。我知道我可以启用" on"使用此命令:set(handles.start_pushbutton,'Enable','on'); 我通过单击"关闭"在子区域中执行此命令。按钮。

function pushbutton_Beenden_Callback(hObject, eventdata, handles)
closereq;
set(handles.start_pushbutton,'Enable','on');

我怎样才能告诉他设置命令但是在主要的gui?

  

错误:引用不存在的字段' start_pushbutton'

1 个答案:

答案 0 :(得分:1)

由于您在{em>主 GUI中定义了start_pushbutton,因此在子GUI的handles结构中无法使用它。您希望在子GUI的handles结构中存储主GUI的句柄。

% From within your main GUI
hfig = subGUI();

% Add the (current) main GUI handle to the subGUI handles
handles = guidata(hfig);

handles.parentGUI = hObject;
guidata(hfig, handles);

然后从subGUI回调:

% Get the GUIDATA from the parent GUI
parentdata = guidata(handles.parentGUI);

% Change the pushbutton property
set(parentdata.start_pushbutton, 'Enable', 'on');

或者您可以在Tag上使用uicontrol,以便您可以从其他GUI中找到它。

% From the GUI that has this button
uicontrol('Tag', 'MyPushButton')

% From the button that was defined in the parent GUI
button = findall(0, 'Tag', 'MyPushButton');
set(button, 'Enable', 'on')