首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环GUI函数

循环GUI函数
EN

Stack Overflow用户
提问于 2014-05-11 12:04:06
回答 1查看 237关注 0票数 0

我只想知道是否有可能高效地循环GUI函数。

代码语言:javascript
复制
function Menu1_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu2_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu3_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    % if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
    function Menu4_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end

现在我有:

代码语言:javascript
复制
HandleNames = {'Menu1','Menu2','Menu3','Menu4'};
for d = 1:4   
    eval('function (HandleNames{d})_Callback(~, ~, ~)');
    eval('function (HandleNames{d})_CreateFcn(hObject, ~, ~)');
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white'); % Set the background color to white
    end
end

但我清楚地知道,eval函数不是很好的实践,它在命令窗口中抛出了一些错误,但仍然像以前一样运行。是有更优雅的方法来做这件事,还是这只是我必须要处理的事情,干杯。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-11 12:33:21

啊,我看你在用向导。这是一个很好的工具,简单,扔掉GUI,但一旦你尝试做任何整洁的事情,你会推动它超越它的限制。幸运的是还有更好的方法。您需要使用编程GUI函数部分或全部构建GUI。因此,对于您感兴趣的特定任务,请尝试如下:

代码语言:javascript
复制
menuSet = {'Hi', 'This is a menu', 'and another', 'neat, huh?'};
for menuIndex = 1:numel(menuSet)
    menuHandle = uimenu(fh,'Label', menuSet{menuIndex);
    % You can use menuHandle here, to manipulate any of the menus
    % properties, or add a sub-menu!
end

您还可以添加子菜单,分配上下文,以及所有其他有趣的东西。我知道有一个学习曲线,但是如果您计划在任何严肃的GUI应用程序中使用MATLAB,我强烈建议学习所有编程GUI函数,其中uimenu只是其中之一。祝好运!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23592379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档