matlab - 如何从代码创建的按钮调用另一个按钮的回调
问题描述
假设我在 MATLAB GUI 上有两个按钮。当我按下 pushMain 时,我想调用 pushChild 按钮的回调。
我可能已经简单地将 pushChild_Callback(hObjects, eventdata, handles) 放在 pushMain 的回调中,但我的问题是我通过代码创建了 pushChild 对象,因此代码上没有单独的回调函数。
handles.pushChild = uicontrol('Style','pushbutton');
handles.pushChild.Callback = {@printA, 1}
% this means when I press on pushChild button, it will print "A = 1"
function printA(src, event, j)
handles = guidata(src);
fprintf('A = %d\n',j);
现在,当我按下 pushMain 时,我想在屏幕上看到“A = 1”。
我试过了:
function pushMain(hObject, eventdata, handles)
fprintf('1\n');
fprintf('2\n');
fprintf('3\n');
handles.pushChild.Callback(); % option 1 -> no error but nothing happens.
handles.pushChild.Callback(hObject, eventdata, handles) % option 2 -> nothing happens
问候。
解决方案
推荐阅读
- php - 2 个日期之间不包括第一天
- android - 谷歌登录游戏失败
- python - Pyomo:使用列表参数化约束
- python - 如何将函数定义为其他函数及其相关参数的总和并拟合参数 [python]
- laravel - auth()->user() 在功能测试时在 ServiceProvider 中返回 null
- javascript - 在 jQuery 中创建的元素不会触发侦听器
- android - EmojiCompat 动态列出表情符号
- swift - 当我在 swiftUI 中打开 TabView 的视图时,onReceive 不执行
- regex - 除了在 perl 中将每个单词放在单独的行上之外,尝试输入格式化的文本文件并删除所有空格
- sql - 查询具有 30 秒时间窗口的运行平均值,向前移动 5 秒