ColorPicker

ColorPicker

Introduction

ColorPicker is a color selector supporting multiple color formats.

Function signature

ColorPicker(
    show_alpha=False,
    color_format="hex",
    widget_id=None,
)
color_picker_default

Parameters

ParametersTypeDescription

show_alpha

bool

Whether to display the alpha slider

color_format

Literal["hex", "hsl", "hsv", "rgb"]

Color format

compact

bool

Make widget compact

widget_id

str

ID of the widget

show_alpha

Determine whether to display the alpha slider.

type: bool

default value: False

color_picker = ColorPicker(show_alpha=True)
show_alpha

color_format

Determine color format(hsl, hsv, hex, rgb).

type: Literal["hex", "hsl", "hsv", "rgb"]

default value: hex

color_picker = ColorPicker(color_format="hsl")
color_format

compact

Make widget compact.

type: bool

default value: False

widget_id

ID of the widget.

type: str

default value: None

Methods and attributes

Attributes and MethodsDescription

get_value()

Return ColorPicker current color

set_value()

Set ColorPicker color

is_show_alpha_enabled()

Check if show_alpha is True or False

enable_show_alpha()

Enable show_alpha

disable_show_alpha()

Disable show_alpha

get_color_format()

Return ColorPicker color format

set_color_format()

Set ColorPicker color format

value_changed()

Handle color change event

Mini App Example

You can find this example in our Github repository:

supervisely-ecosystem/ui-widgets-demos/input/007_color_picker/src/main.py

Import libraries

import os
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Card, Container, ColorPicker, Text

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance:

load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api()

Initialize ColorPicker and Text widgets

color_picker = ColorPicker(show_alpha=False, color_format="hex", compact=False)
color_info = Text("Current color: #20A0FF", "info")
text = Text("Hello, World!", color="#20A0FF", font_size=22)

Create app layout

Prepare a layout for app using Card widget with the content parameter.

layout = Card(
    "Color Picker",
    content=Container([color_picker, color_info, text]),
)

Create app using layout

Create an app object with layout parameter.

app = sly.Application(layout=layout)

Last updated