.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:
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
|
Source code in wigglystuff/paint.py
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. |