Skip to content

Color Palette

Use a color palette to pick one color from a group of colors.

Basic

Set options= with mode='color' to show a color palette.

The option's value must be a valid color in one of the formats described in the previous example.

Unlike the Color Picker, the Color Palette returns the value of the chosen option, and not a (r,g,b,a) tuple.

color = view(box('Choose a color', mode='color', options=[
    option('#ff0000', 'Red'),
    option('#00ff00', 'Green'),
    option('#0000ff', 'Blue'),
    option('#ffff00', 'Yellow'),
    option('#00ffff', 'Cyan'),
    option('#ff00ff', 'Magenta'),
]))
view(f'You chose {color}.')

Screenshot

Set initial color

Set value= to pre-select an option having that color value.

color = view(box('Choose a color', mode='color', value='#0000ff', options=[
    option('#ff0000', 'Red'),
    option('#00ff00', 'Green'),
    option('#0000ff', 'Blue'),
    option('#ffff00', 'Yellow'),
    option('#00ffff', 'Cyan'),
    option('#ff00ff', 'Magenta'),
]))
view(f'You chose {color}.')

Screenshot

Mark colors as selected

Alternatively, set selected=True to pre-select a color in the palette.

color = view(box('Choose a color', mode='color', options=[
    option('#ff0000', 'Red'),
    option('#00ff00', 'Green'),
    option('#0000ff', 'Blue', selected=True),
    option('#ffff00', 'Yellow'),
    option('#00ffff', 'Cyan'),
    option('#ff00ff', 'Magenta'),
]))
view(f'You chose {color}.')

Screenshot

Handle changes immediately

Add live to mode to handle changes immediately.

color = '#0000ff'
while True:
    color = view(
        box(
            'Choose a color',
            mode='live color',
            value=color,
            options=[
                option('#ff0000', 'Red'),
                option('#00ff00', 'Green'),
                option('#0000ff', 'Blue'),
                option('#ffff00', 'Yellow'),
                option('#00ffff', 'Cyan'),
                option('#ff00ff', 'Magenta'),
            ],
        ),
        f'You chose {color}.'
    )

Screenshot

Disable

Set disabled=True to disable.

view(box(
    'Choose a color',
    mode='color',
    options=[
        option('#ff0000', 'Red'),
        option('#00ff00', 'Green'),
        option('#0000ff', 'Blue'),
    ],
    disabled=True,
))

Screenshot