如何使GUI按钮打开/关闭另一个GUI(How to make a GUI pushbutton open/close another GUI)

编程入门 行业动态 更新时间:2024-10-28 15:24:17
如何使GUI按钮打开/关闭另一个GUI(How to make a GUI pushbutton open/close another GUI)

我有一个名为GUI_main的GUI,其中有一个名为pushbutton_GUI_main 。 我目前实现了以下回调函数:

function pushbutton_GUI_main_Callback(hObject, eventdata, handles) GUI_sub

其中GUI_sub是另一个在单击pushbutton_GUI_main时打开的GUI。 但是,我想要以下内容:

function pushbutton_GUI_main_Callback(hObject, eventdata, handles) if (GUI_sub == open) close(GUI_sub) else GUI_sub

也就是说,使用pushbutton_GUI_main我希望能够打开关闭GUI_sub 。

I have a GUI called GUI_main in which I have a pushbutton called pushbutton_GUI_main. I currently have the following callback function implemented:

function pushbutton_GUI_main_Callback(hObject, eventdata, handles) GUI_sub

Where GUI_sub is another GUI that opens when you click on pushbutton_GUI_main. However, I want something like the following:

function pushbutton_GUI_main_Callback(hObject, eventdata, handles) if (GUI_sub == open) close(GUI_sub) else GUI_sub

That is, with pushbutton_GUI_main I want to be able to open and close GUI_sub.

最满意答案

正如excaza所说, 句柄是在GUI中传递数据或信息的好方法。 另一种方式,如果由于某种原因你不想存储GUI句柄,也许如果可以独立创建GUI_sub就是搜索图形句柄。

subGuiH = findall(0,'Name','GUI_sub'); if ~isempty(subGuiH) close(subGuiH); end GUI_sub;

可以通过添加来缩小搜索范围

findall(0,'Type','figure','Name','GUI_sub')

根据您的Matlab版本,您还可以结帐

As excaza says, handles is a great way to pass data or information in a GUI. Another way, if you for some reason don't want to store the GUI handle, perhaps if the GUI_sub could be created independently is to search for the figure handle.

subGuiH = findall(0,'Name','GUI_sub'); if ~isempty(subGuiH) close(subGuiH); end GUI_sub;

The search could be narrowed by adding

findall(0,'Type','figure','Name','GUI_sub')

Depending on your Matlab version, you could also checkout groot

更多推荐

本文发布于:2023-07-31 15:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345270.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   GUI   pushbutton   close   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!