MATLAB GUI pullow displays a push down button instead of disabled

I run the instruction drawnowfrom the callback function in the MATLAB GUI to update the state of the button. At the beginning of the callback (with a high runtime), I change the properties of the button and force update with drawnow. If configured correctly, the button remains “pressed” instead of “disabled”. After the callback is completed, the button is updated again and is now displayed as “disabled”.

Take the following working example of minmal (not):

function simple_example()
h = figure();
% add a button, give it some properties and a callback
uicontrol(h,...
    'Style','pushbutton',...
    'String','I am enabled',...
    'Units','normalized',...
    'Position',[0.5 0.5 0.4 0.4],...
    'Callback',@btn_callback);
end

function btn_callback(hObject, ~)
    set(hObject,'Enable','off');
    set(hObject,'String','I am disabled');
    drawnow;
    pause(3);
end

Is there a way to change this behavior and disable the button during callback?

+4
source share
1

uibuttongroup:

function simple_example()
h = figure();
b = uibuttongroup('Position',[0.5 0.5 0.4 0.4]);
bgcolor = b.BackgroundColor;
% add a button, give it some properties and a callback
uicontrol(b,...
    'Style','pushbutton',...
    'String','I am enabled',...
    'Units','normalized',...
    'Position',[-0.05 -0.05 1.1 1.1],...
    'Callback',@btn_callback);
end

function btn_callback(hObject, ~)
    set(hObject,'Enable','off');
    set(hObject,'String','I am disabled');
    drawnow;
    pause(3);
end

uibuttongroup, uibuttons, , uibuttongroup, .

, . , uicontrolgroup.

:

. OS X , . Windows, , , , , , , . Ubuntu, , .

+1

Source: https://habr.com/ru/post/1616852/


All Articles