MATLAB Type “guide” in the command line. Use guide to create a GUI with two push
ID: 3867403 • Letter: M
Question
MATLAB
Type “guide” in the command line. Use guide to create a GUI with two pushbuttons. Change the text of both push buttons to be blank, and change their colors to white. Then save. In the resulting skeleton code, find the pushbutton callback functions. Within those functions, write code that will cause one button to turn red and say “push me” if the other button is pressed. When a button is pressed, it should go back to being white with not text. Submit only the code for the two pushbutton callback functions, and not the entire GUI skeleton code. You need not submit a printout of your GUI
Explanation / Answer
function colorsButtons
clf;
btn1=uicontrol('Style',...
'pushbutton',...
'String','',...
'Position',[10 350 100 30],...
'BackgroundColor','[255 255 255]'
'HandleVisibility','on',...
'Tag','Button1',...
'Callback',@pushbutton_Callback);
btn2=uicontrol('Style','pushbutton',...
'String','',...
'Position',[10 250 100 30],...
'BackgroundColor','[255 255 255]'
'HandleVisibility','on',...
'Tag','Button2',...
'Callback',@pushbutton_Callback);
end
function pushbutton_Callback(hObject,callbackdata)
handles = guihandles(hObject);
if(hObject.Tag === 'Button1')
handles.Button1.String = 'Push me';
handles.Button2.String = ' ';
handles.Button1.BackgroundColor = '[255 0 0]';
handles.Button2.BackgroundColor = '[255 255 255]';
else
handles.Button2.String = 'Push me';
handles.Button1.String = ' ';
handles.Button2.BackgroundColor = '[255 0 0]';
handles.Button1.BackgroundColor = '[255 255 255]';
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.