How can I create a color picker with 2 color dimensions (hue and brightness)?

Hi everyone,

I’m currently trying to build a color picker tool that dynamically changes the color of a stimulus the subject sees on their screen. I used the slider tool in the Builder, but it seems like I can only set the color range to rgb, hsv, dkl, and lms, but those contain only the color hues, not different levels of brightness.
What I’d like to do is let the subject pick a certain hue (e.g. blue, yellow, green,…) and then adjust the brightness of the color using a color picker. Is there some way to do this in PsychoPy?

Thanks in advance!


This depends how you define “brightness” - you could set the colours in RGB and add/subtract equally from each value.

I’m currently working on a bit of a change to how colours work in PsychoPy, this is very much in the development stage but you’re welcome to give it a try! In 2020.2.5 (which should be out in the next few days) the classes and methods for colours will be included, but not linked to anything yet. You can however use these as a medium to edit colours as follows:

# Import the Color class
from psychopy.colors import Color
# Create a color (in this case, mid grey specified by name)
myColor = Color('grey', colorSpace='named')
# Set the stimulus to be this color in rgb by accessing its "rgb" property
myStim.color = myColor.rgb
# Check against whatever condition you're using
if someCondition:
    # Add whatever value to the brightness of the color - this will uniformly increase each rgb value
    myColor.brightness += 0.1
    # Once again set the color of the stimulus using rgb, this will supply it with the new value
    myStim.color = myColor.rgb

you’d link this to a slider like this:

myColor.brightness = mySlider.value

(assuming mySlider has a range of 0 to 1)

Once properly integrated (hopefully in 2021.0) you will be able to just do:

myStim.color = 'grey'
if someCondition:
    myStim._foreColor.brightness += 0.1

and the rest will happen behind the scenes, but I’ve got a bit of work to do to make that happen!

1 Like

Thank you so much for your detailed answer! I’m downloading the new version of PsychPy rn and I’ll try this later! :slight_smile:

Hi @TParsons,

I just tried to use this in my experiment, but it seems like I can’t import the Color class from psychopy.colors. I don’t know why this happens, I just copied the code above.

Another weird thing that happened: If I import the whole psychopy.colors package (hopefully containing the Color class as well), the object myColor won’t work. I checked the documentation and I’m not sure whether the attribute colorSpace should be just space instead. :see_no_evil:

Could you maybe help me again? :slight_smile:
Thanks in advance!


Unfortunately Color didn’t make it to the 2020.2.5 release, it was too big of a change to safely put out in a bug fix release in the end. However, if you’re always going to be using PsychoPy on the same machine, you can add it manually!

Go to wherever PsychoPy is installed (probably Program Files, look for the folder PsychoPy3), then Lib -> site-packages -> psychopy. In that folder, copy this file:

and say yes to replacing the file already there. This is the file Python will look for when you import psychopy.colors, so if it finds the version with Color classes in then that’s what it’ll use :slight_smile:
1 Like

I’ve just seen you marked the topic as solved so wanted to provide an update: psychopy.color.Color is in PsychoPy now! Updating to the latest version (at time of writing, 2022.2.3) will mean you can adjust brightness like this:

myStim._foreColor.rgb = myStim._foreColor.rgb + 0.1
1 Like

Yes sorry, I forgot to close the topic. ^^ Thanks for the update, though, that’s super useful!