.md →
Paint API#
Bases: AnyWidget
Notebook-friendly drawing canvas with brush, marker, eraser, undo, and PIL helpers.
Pass rainbow_brush=True to add an extra spray-paint tool that scatters
randomly-colored particles around the cursor — handy for generating noisy,
multi-color masks for image models.
Examples:
import marimo as mo
from wigglystuff import Paint
paint = mo.ui.anywidget(Paint(width=400, height=300))
paint
Create a Paint widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Canvas height in pixels. |
DEFAULT_HEIGHT
|
width
|
int
|
Canvas width in pixels (ignored when |
DEFAULT_WIDTH
|
store_background
|
bool
|
Persist previous strokes when background changes. |
True
|
init_image
|
Optional[Any]
|
Optional path/URL/PIL image/bytes to preload. |
None
|
rainbow_brush
|
bool
|
Show an extra spray tool that paints randomly-colored particles. |
False
|
brush
|
bool
|
Show the thin brush tool. |
True
|
marker
|
bool
|
Show the thick marker tool. |
True
|
eraser
|
bool
|
Show the eraser tool. |
True
|
color_picker
|
bool
|
Show the color picker (hide it to lock drawing to |
True
|
color
|
str
|
Drawing color as a hex string; two-way synced with the picker. |
'#000000'
|
Source code in wigglystuff/paint.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
get_base64 #
get_pil #
Return the current drawing as a PIL Image.
replace_with_pil #
Replace the canvas contents with a PIL Image.
Wipes any existing strokes — the canvas has no separate background layer.
The image is resized to (self.width, self.height) if needed.
Source code in wigglystuff/paint.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
base64 |
str |
PNG data URL or raw base64 payload. |
width |
int |
Canvas width in pixels. |
height |
int |
Canvas height in pixels. |
store_background |
bool |
Persist strokes when background changes. |
rainbow_brush |
bool |
Show the rainbow spray tool (default off). |
brush |
bool |
Show the thin brush tool. |
marker |
bool |
Show the thick marker tool. |
eraser |
bool |
Show the eraser tool. |
color_picker |
bool |
Show the color picker. |
color |
str |
Drawing color (hex); two-way synced with the picker. |