Skip to content

ColorChooser

Bases: Frame

Color chooser widget with multiple selection modes.

__init__

__init__(
    master: Optional[Misc],
    initial_color: Optional[str] = None,
    padding: Optional[int] = None,
) -> None

Create a color chooser widget.

The chooser offers: - Advanced tab: spectrum with hue/saturation and luminance slider. - Themed tab: swatches for theme colors and shades. - Standard tab: common colors and shades.

Includes RGB/HSL/Hex inputs, live preview, and optional dropper.

Parameters:

Name Type Description Default
master Optional[Misc]

Parent widget.

required
initial_color Optional[str]

Initial color string; defaults to theme background.

None
padding Optional[int]

Padding around the chooser.

None

create_spectrum

create_spectrum(master: Misc) -> ttk.Canvas

Create the color spectrum canvas

create_spectrum_indicator

create_spectrum_indicator() -> None

Create a square indicator that displays in the position of the selected color

create_swatches

create_swatches(
    master: Misc, colors: List[str]
) -> ttk.Frame

Create a grid of color swatches

create_preview

create_preview(master: Misc) -> ttk.Frame

Create the preview frame for original and new colors

create_value_inputs

create_value_inputs(master: Misc) -> ttk.Frame

Create color value input widgets

create_luminance_scale

create_luminance_scale(master: Misc) -> ttk.Canvas

Create the color luminance canvas

create_luminance_indicator

create_luminance_indicator() -> None

Create an indicator that displays in the position of the luminance value

coords_from_color

coords_from_color(hexcolor: str) -> Tuple[float, float]

Get the coordinates on the color spectrum from the color value

color_from_coords

color_from_coords(x: int, y: int)

Get the color value from the mouse position in the color spectrum

set_variables

set_variables(
    h: int, s: int, l: int, r: int, g: int, b: int, hx: str
) -> None

Update the color value variables

get_variables

get_variables()

Get the values of all color models and return a tuple of color values

update_preview

update_preview() -> None

Update the color in the preview frame

update_luminance_scale

update_luminance_scale() -> None

Update the luminance scale with the change in hue and saturation

update_luminance_indicator

update_luminance_indicator() -> None

Update the position of the luminance indicator

update_spectrum_indicator

update_spectrum_indicator() -> None

Move the spectrum indicator to a new location

sync_color_values

sync_color_values(model)

Callback for when a color value changes. A change in one value will automatically update the other values so that all color models remain in sync.

on_entry_value_change

on_entry_value_change(widget: Spinbox, model: Any) -> None

Update the widget colors when the color value input is changed

on_press_swatch

on_press_swatch(event: Event) -> None

Update the widget colors when a color swatch is clicked.

on_spectrum_interaction

on_spectrum_interaction(event: Event) -> None

Update the widget colors when the color spectrum canvas is pressed

on_luminance_interaction

on_luminance_interaction(event: Event) -> None

Update the widget colors when the color luminance scale is pressed