Set color using "Set Property" script builder

Hello,

How do I properly enter a color value into the “To this value:” field of the Set Property script builder? I am trying to change the foreground color of a label on mouse entered event. I thought this would be very simple using Set Property, but it doesn’t accept my value format. I tried entering the value the following ways:
0,0,0
(0,0,0)
system.gui.color(0,0,0)
color(0,0,0)
“0,0,0”

None of them work, obviously. It’s giving me the this error:

[ Traceback (most recent call last):
File “event:mouseEntered”, line 7, in
TypeError: can’t convert u’0,0,0’ to java.awt.Color ]

Any help would be much appreciated.

Thanks.

You can not do this out of the box from the script builder.

From the manual:

The new value can be a literal value or the value of any other property

You have 2 options:

1.) Create a custom property on the label (or root container), and set the property to that color.
2.) Use the script editor

Good news though, you can use the script builder to do most of the work for you. Just enter system.gui.color(0,0,0,255) into the ‘To this value’ field and then switch over to the script editor tab.

You’ll be presented with something like this:

# This script was generated automatically by the property set
# script builder. You may modify this script, but if you do,
# you will not be able to use the property set builder to update
# this script without overwriting your changes.

value = u'system.gui.color(0,0,0,255)'
event.source.foreground = value

Now all you need to do us remove the string identifiers from the code so that you end up with this:

# This script was generated automatically by the property set
# script builder. You may modify this script, but if you do,
# you will not be able to use the property set builder to update
# this script without overwriting your changes.

value = system.gui.color(0,0,0,255)
event.source.foreground = value

Now when your mouse enters the label the foreground color will be changed.

4 Likes

Got it. Thanks lrose!