Color picker
ui.ColorPicker is a component that picks a color with alpha, a linear gradient (stops you add, drag and remove, plus an angle) or a fill with an opacity mask. on_change receives an event whose value is a "#rrggbb[aa]" string, a pz.Gradient or a pz.Paint, all valid backgrounds. ui.color_swatch shows any of them over a checkerboard.
ui.ColorPicker · Category: Forms · Full reference →


pz.row([ ui.ColorPicker(value="#3b82f6cc", on_change=on_change), pz.column([ ui.color_swatch("#3b82f6", size=28), ui.color_swatch("#a1c181aa", size=28), ui.color_swatch(pz.Gradient(["#f97316", "#7c3aed"], angle=90), size=28), ], spacing=8),], spacing=16)When to use
Section titled “When to use”- For theme editors, drawing apps and style properties.
- Show a
color_swatchand open the picker in a Popover when it is pressed.
import pyzed as pzfrom pyzed import ui
class Styles(pz.App): def __init__(self): self.fill = "#3b82f6"
def view(self): return pz.row([ ui.ColorPicker(value=self.fill, on_change=lambda e: setattr(self, "fill", e.value)), pz.container(width=120, height=120, bg=self.fill, radius=8), ], spacing=16)Variants
Section titled “Variants”Options
Section titled “Options”

Code
ui.ColorPicker(value="#3b82f6cc", on_change=on_change)

alpha=False, gradients=False, masks=FalseCode
ui.ColorPicker(value="#a1c181", alpha=False, gradients=False, masks=False, on_change=on_change)![Color picker: swatches=[...]](/pyzed/library/color-picker-v1-3.dark.webp)
![Color picker: swatches=[...]](/pyzed/library/color-picker-v1-3.light.webp)
swatches=[...]Code
ui.ColorPicker(value="#e5c07b", gradients=False, masks=False, swatches=["#e06c75", "#e5c07b", "#98c379", "#61afef", "#c678dd"], on_change=on_change)Swatches
Section titled “Swatches”A swatch draws any color, gradient or paint over a checkerboard, so transparency shows.


Code
ui.color_swatch("#3b82f6", size=32)

Code
ui.color_swatch("#a1c181aa", size=32)

pz.GradientCode
ui.color_swatch(pz.Gradient(["#f97316", "#7c3aed"], angle=90), size=32)

ui.checkerboardCode
ui.checkerboard(96, 48, size=8)Events
Section titled “Events”Color picker has 2 events of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
It is a pz.Component, so it also raises on_mount and on_unmount, and its handlers get a pz.Event whose value holds the data.
| Event | Of | Handler gets | When |
|---|---|---|---|
on_change |
ui.ColorPicker |
(event) |
Receives event.value. |
on_press |
ui.color_swatch |
() |
Makes it clickable. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Styles(pz.App): def __init__(self): self.fill = "#3b82f6"
def picked(self, event): # a pz.Component: the color is event.value self.fill = event.value
def view(self): return pz.row([ ui.ColorPicker(value=self.fill, on_change=self.picked), pz.container(width=80, height=80, bg=self.fill, radius=8), ui.color_swatch("#ef4444", on_press=lambda: setattr(self, "fill", "#ef4444")), ], spacing=16)from dataclasses import dataclass
@dataclassclass Fill: color: str
class Styles(pz.App): fill = "#3b82f6"
def update(self, message): match message: case Fill(color): self.fill = color
def view(self): return pz.row([ui.ColorPicker(value=self.fill, on_change=lambda e: Fill(e.value)), ui.color_swatch("#ef4444", on_press=Fill("#ef4444"))], spacing=16)from dataclasses import dataclass
@dataclass(frozen=True)class State: fill: str = "#3b82f6"
def view(state, set_state): return pz.row([ui.ColorPicker(value=state.fill, on_change=lambda e: set_state(fill=e.value)), pz.container(width=80, height=80, bg=state.fill, radius=8)], spacing=16)Properties and API
Section titled “Properties and API”ui.ColorPicker
Section titled “ui.ColorPicker”class ColorPickerA component that picks a color with alpha, a linear gradient (stops you add, drag and remove, plus an angle) or a fill with an opacity mask. on_change gets a "#rrggbb[aa]" string, a pz.Gradient or a pz.Paint, all valid as a background. Pass the picked value back as value. See Styles.
| Property | Default | Description |
|---|---|---|
value |
"#3b82f6" |
A color, theme token, pz.Gradient or pz.Paint. |
alpha |
True |
Shows the alpha bar and field. |
gradients |
True |
Shows the Solid/Gradient switch. |
masks |
True |
Shows the mask editor. |
swatches |
None |
Quick colors (default: the theme’s accent and status colors). |
Events: on_change (events).
ui.color_swatch
Section titled “ui.color_swatch”color_swatch(value, *, size=20, on_press=None)A small square showing a color, gradient or paint over a checkerboard.
| Property | Default | Description |
|---|---|---|
value |
required | What to show. |
size |
20 |
Side in pixels. |
Events: on_press (events).
ui.checkerboard
Section titled “ui.checkerboard”checkerboard(width, height, size=6)A light/dark checkerboard to draw under translucent colors.
| Property | Default | Description |
|---|---|---|
width |
required | Width. |
height |
required | Height. |
size |
6 |
Cell size. |