我目前正在使用 mathlab GUIDE 创建一个 GUI。由于 GUI 很慢,我想添加一个edit_textuicontrol 以显示 GUI 是否正在运行。
例如,我有一个push_button可以更改轴上的绘图。当用户点击这个按钮时,GUI 需要几秒钟来执行新的绘图。我想要做的是在按下按钮后立即edit_text使用字符串设置。'running'当回调完成并绘制绘图时,我想edit_text用另一个字符串设置 : 'ready'。
我使用了以下代码:
function push_button_Callback(hObject, eventdata, handles)
% hObject handle to push_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.edit_text,'String','Running...');
%a bunch of code...
set(handles.edit_text,'String','Ready.');
guidata(hObject,handles);
我希望一旦调用回调,GUI 会显示'running...'在我的edit_text. 显然我错了。运行 GUI 并按下push_button绘图时,绘图会发生变化,但edit_text保持不变。
ButtonDownFcn然后我使用回调尝试了其他方法。我的想法是后一个回调将在实际回调之前执行(如上所述)。这是代码:
function push_button_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to push_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.edit_text,'String','Running...');
guidata(hObject,handles);
问题是ButtonDownFcn回调不是每次都执行。正如 GUIDE 所说的后者回调:
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over str22.
显然我希望我push_button的启用,否则它不会按我想要的方式工作。所以我不知道还能尝试什么。
有人知道我怎么能做到这一点吗?