# Rgb hsv values for window buttons

**URL:** https://forum.highend3d.com/t/rgb-hsv-values-for-window-buttons/173
**Category:** Maya
**Tags:** mel
**Created:** [April 12, 2016, 7:27am UTC](https://forum.highend3d.com/t/rgb-hsv-values-for-window-buttons/173 "2016-04-12T07:27:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![joel-mann](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@joel-mann](https://forum.highend3d.com/u/joel-mann)
#### Post date: [April 12, 2016, 7:27am UTC](https://forum.highend3d.com/t/rgb-hsv-values-for-window-buttons/173/1 "2016-04-12T07:27:42Z")

</div>

Hey everyone. &nbsp;I've been tinkering with mel lately, paritluatly making windows with buttons to perform various functions. &nbsp;Im wanting to color code my buttons, but not getting the resluts I'd like. &nbsp;Ive been using bgc values, but its been difficult getting the exact value I need. &nbsp;Is there a way to apply the rgb and hsv values to a button, and if so, how? &nbsp;Thanks!

---

<div class="post-metadata">

### Author: ![charliewales](https://forum.highend3d.com/user_avatar/forum.highend3d.com/charliewales/32/4_2.png) [@charliewales](https://forum.highend3d.com/u/charliewales)
#### Post date: [April 13, 2016, 4:55am UTC](https://forum.highend3d.com/t/rgb-hsv-values-for-window-buttons/173/2 "2016-04-13T04:55:59Z")

</div>

Just make a conversion on the fly by dividing you rgb values by 255 to get a normalized value between 0 and 1 (note that I use 255.0 instead of 255 to obtain a float value instead of an int:

test:  
&nbsp;&nbsp;&nbsp; print (171/255);  
&nbsp;&nbsp;&nbsp; //result 0

&nbsp;&nbsp;&nbsp; print (171/255.0);  
&nbsp;&nbsp;&nbsp; //result 0.670588

* * *

// ex. code for rgb color (171, 208, 188)

{  
&nbsp;&nbsp;&nbsp; window -tlb 1 -t "Use RGB values";  
&nbsp;&nbsp;&nbsp; rowLayout -adj 1;  
&nbsp;&nbsp;&nbsp; button -l "rgb(171,208,188)" -bgc (171/255.0) (208/255.0) (188/255.0);  
&nbsp;&nbsp;&nbsp; showWindow;  
}

![](https://forum.highend3d.com/system/screenshots/316335/original/rgb.png?1460523359)

---

<div class="post-metadata">

### Author: ![bfx](https://forum.highend3d.com/user_avatar/forum.highend3d.com/bfx/32/3_2.png) [@bfx](https://forum.highend3d.com/u/bfx)
#### Post date: [April 15, 2016, 3:30am UTC](https://forum.highend3d.com/t/rgb-hsv-values-for-window-buttons/173/3 "2016-04-15T03:30:55Z")

</div>

colorBuddy

```auto
global proc colorMe(){
    string $window = "colorBuddy|panel|"; string $rh[] ={"r","h"};
    for ($abc in {"A","B","C","D","E"}){
        float $rgb[2] = `colorSliderGrp -q -rgb ($window+$abc)`;
        float $hsv[2] = `colorSliderGrp -q -hsv ($window+$abc)`;
        $rgbhsv[0] = ($rgb[0]+" "+$rgb[1]+" "+$rgb[2]);
        $rgbhsv[1] = ($hsv[0]+" "+$hsv[1]+" "+$hsv[2]);
        for ($n=0;$n<=1;$n++){textField -e -tx $rgbhsv[$n] ($window+$rh[$n]+$abc);}
    }
}
 
global proc makeColorWindow(){
if (`window -ex colorBuddy`) deleteUI colorBuddy;
$i = 0.0;
window -w 700 -t "colorBuddy" colorBuddy;
    rowColumnLayout -nc 3 panel;
    for ($abc in {"A","B","C","D","E"}){
        textField -w 250 ("r"+$abc); colorSliderGrp -cc colorMe -rgb $i $i $i $abc;textField -w 250 ("h"+$abc); $i+=0.25;}
        setParent..;       
    setParent..;
    colorMe;
showWindow;
}
 
makeColorWindow;
```

![](https://forum.highend3d.com/system/screenshots/316340/original/Screenshot-12.png?1463537333)
