Color to string

Is there any way to read the color from the Power table and convert it to string, where R,G and B values can be read?


I need to store these values to MySql database as a string.

Click on the little color wheel.

I forgot to mention that I need to handle the Color datatype in scripting.

Now I’m reading all the values from COLOR column using the following script


table = event.source.data
data1 = system.dataset.toPyDataSet(table)
for row in data1:
c = row[“COLOR”]

c is then stored to database. In the database the field looks like this


Is there any way to convert the value c to understandable string?

It looks like you are actually storing the Java color object in the database.
If you want to store it as a readable string, you can give a try to the str() function. It should give you a string like this : “java.awt.Color[r=xxx,g=xxx,b=xxx]”
Storing str© instead of c should do the trick.

Alternately, if you want a little bit nicer format (or perhaps separate columns) the Color object also has various get* methods that are useful:

color = event.source.parent.getComponent('Button 1').buttonBG
print color.getRed()
print color.getGreen()
print color.getBlue()
print color.getAlpha()
2 Likes