How can I change color of Push Button in Simulink GUI or add a picture?

1 回表示 (過去 30 日間)
Diana Nikitaeva
Diana Nikitaeva 2020 年 8 月 8 日
コメント済み: Diana Nikitaeva 2020 年 8 月 13 日
I have a push button in Simulink GUI, but I can't change its color. When I try to set the background or foreground colors from the properties menu, it doesn't display on the button - it still stays white.
Is there a way to do it programmatically? I tried using the MATLAB GUI push button options, but that approach doesn't work with Simulink.
Or is there a way to add a picture in the button instead of only text?

回答 (1 件)

Gouri Chennuru
Gouri Chennuru 2020 年 8 月 12 日
Hi Diana,
Yes, You can update the background color by using the set function which is used to set all the graphics object properties.
You can set the background color to the push button in this manner,
set(Objectname,'BackgroundColor',[0,0,0]);
You can also set the background image to the push button using set function as follows,
set(Objectname, 'CData', bg_image);
Hope this Helps!
  1 件のコメント
Diana Nikitaeva
Diana Nikitaeva 2020 年 8 月 13 日
I tried doing both and got the block handle through getSimulinkBlockHandle. But, it still doesn't work. Using
set(handle,'BackgroundColor',[0,1,0])
Gives the following error:
Invalid setting in PushButtonBlock block 'Push Button1' for parameter 'BackgroundColor'
I went ahead and set the color array to a color name and it went through but the color of the button didn't change. However, the parameter itself says that it did.
I also tried using the CData and Simulink returned an error saying:
PushButtonBlock block does not have a parameter named 'CData'
Any other ideas?
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Model Editing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by