Initially Disabled Button Group when using GUI / GUIDE

조회 수: 9 (최근 30일)
Matt C
Matt C 2016년 9월 8일
답변: Matt C 2016년 9월 8일
Hello all,
I have an easy GUI question that I can't find the answer to - I can't figure out where to specify that a button group is initially disabled instead of enabled.
In my simplified example, I want to have a check-box that has a disabled (greyed-out) button group below it, until the check-box is selected by the user.
I have gone over similar questions in the forum, and I have found that the way to change the status of the button group is:
function MattsCheckBox_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'on');
else
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'off');
end
When I click back and forth on the check-box, sure enough my button group enables and disables. However, before I do any clicking of the check box, the button group starts enabled instead of disabled. Where (or how) do I initialize the button group so that it starts disabled and greyed-out?

채택된 답변

Matt C
Matt C 2016년 9월 8일
I figured it out. There isn't any default disablement of the Button Group - it needs to be coded into the disabled position at the beginning of the code under the _OpeningFcn function. Here is the code:
function MattsTestScript_OpeningFcn(hObject, eventdata, handles, varargin) % Default line produced by GUIDE
handles.output = hObject; % Default line produced by GUIDE
guidata(hObject, handles); % Default line produced by GUIDE
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'off'); % HERE IT IS

추가 답변 (1개)

mbonus
mbonus 2016년 9월 8일
If the value you are checking in the if statement is true when the GUI starts up, that may be causing the button group to start enabled. For the check box set the value property to 0. Also check to make sure the button group is initialized to 'enable' 'off'. From Guide you should be able to right click the objects and changer their properties, I believe if you hardcode it during the initialization in the code it will work as well, not sure because I don't use Guide.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by