简体   繁体   English

uiwait颜色按钮-Matlab

[英]uiwait color button - Matlab

I have this small Matlab code: 我有这个小的Matlab代码:

uiwait(warndlg('Try 1.  Click OK to continue'));
uiwait(msgbox('Try 2'));

Is it possible to change the color of the OK button to another color (eg, dark gray)? 是否可以将“确定”按钮的颜色更改为另一种颜色(例如,深灰色)?

If you want to change the color of the OK button (and not of the message box), you need to access the Children of that message box first and change the BackgroundColor property. 如果你想改变OK按钮(而不是消息框)的颜色,你需要访问Children :第一,消息框,并更改BackgroundColor属性。 For a dark gray box I'll use the RGB triplet [.2 .2 .2] 对于深灰色框,我将使用RGB三元组[.2 .2 .2]

Therefore: 因此:

hMsg=warndlg('Try 1.  Click OK to continue');

%// Get children
Children = get(hMsg,'Children');

%// The OK button is the 1st
OKButton = Children(1);

set(OKButton,'BackgroundColor',[.2 .2 .2])

uiwait(hMsg) %// Wait for button click; needed if you want code to stop. Thanks Jonas.

Output: 输出:

在此处输入图片说明

Of course doing it in one go yields the same result: 当然,一劳永逸地产生相同的结果:

set(Children(1),'BackgroundColor',[.2 .2 .2])

To change the color of the warndlg pushbutton you have to first get the handle of the pushbutton. 要更改warndlg按钮的颜色,您必须首先获取按钮的handle

To get the handle of the pushbutton you need the handle of the warndlg . 要获得按钮的handle ,您需要warndlghandle

To get the handle of the of the warndlg you need to modify your code as follows: 要获取warndlg的句柄,您需要按以下方式修改代码:

% Create the warning dialog figure and get its handle
h=warndlg('Try 1.  Click OK to continue')
% Find the warning dialog figure pushbutton handle
wh=findobj(h,'style','pushbutton')
% Set the pushbutton background color to "dark gray"
set(wh,'BackgroundColor',[.5 .5 .5])
% Set the pushbutton foreground color to "white"
set(wh,'foregroundColor',[1 1 1])
% Call uiwait for the warning dialog figur
uiwait(h)

Hope this helps. 希望这可以帮助。

试试功能集(hMsg,'color','white');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM