Change background color in pushbutton [Matlab-GUI]

Hi! I need change color of pushbutton when I choose this pushbutton. For example, I select pushbutton1(radiobutton1) and its color changes to green. In same way, color of others pushbutton changes to red. I have 80 pushbuttons, is there any way to make this change at once through a cycle or do I have to write these lines of code for all of them?
case 'radiobutton1'
set(handles.pushbutton1,'BackgroundColor','green');
set(handles.pushbutton2,'BackgroundColor','red');
set(handles.pushbutton3,'BackgroundColor','red');
....

 채택된 답변

Orion
Orion 2014년 10월 6일

1 개 추천

Hi,
You have to do something like this :
function pushbutton1_Callback(hObject, eventdata, handles)
% Get the handles of all pushbuttons and radiobuttons
PushAndRadioButtons = [findall(gcf,'Style','Pushbutton');findall(gcf,'Style','radiobutton')];
% Change to red all these buttons
set(PushAndRadioButtons,'Backgroundcolor','r');
% Set to green the current button
set(gcbo,'Backgroundcolor','g');
You just have to put this code in each callback function of your buttons.

댓글 수: 2

Joao
Joao 2014년 10월 6일
Thanks!
Gry
Gry 2014년 11월 11일
What if you only want the colour off the pushbutton to change when you click it, and once you click another pushbutton the colour goes back, and the next pushbutton you clicked gets a colour change.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Josh
Josh 2014년 12월 23일
편집: Josh 2014년 12월 23일

0 개 추천

The default pushbutton background color is the window's two-shade-of-gray as shown in the attached pic. I would like to keep this two shades with other colors (e.g. green/light green) that I pick using the BackgroundColor property. How do I do it?
edit: For some reason the picture is not attached, but I'm sure you know what I'm talking about...

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2014년 10월 5일

편집:

2014년 12월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by