ipycanvas

raw JSON →
0.14.3 verified Mon Apr 27 auth: no python

Interactive widgets library exposing the browser's Canvas API for Jupyter notebooks and JupyterLab. Current version 0.14.3. Release cadence: irregular, with multiple releases per year.

pip install ipycanvas
error ModuleNotFoundError: No module named 'ipycanvas'
cause ipycanvas is not installed.
fix
Run pip install ipycanvas or conda install -c conda-forge ipycanvas.
error ipycanvas is not displayed in Jupyter notebook
cause The ipywidgets extension may not be enabled or the notebook needs a restart.
fix
Run jupyter nbextension enable --py widgetsnbextension or restart the kernel.
breaking In version 0.12.0, the deprecated `size` property was removed. Use `width` and `height` instead.
fix Replace `canvas.size = (200, 200)` with `canvas.width = 200` and `canvas.height = 200`.
gotcha ipycanvas does not support the full HTML5 Canvas API; only a subset of methods is implemented. For example, `getImageData` returns a list instead of ImageData object.
fix Check the documentation for supported methods; use `canvas.get_image_data(x, y, w, h)` which returns a list of RGBA values.
conda install -c conda-forge ipycanvas

Create a canvas, set fill style, draw a rectangle, and display.

from ipycanvas import Canvas

canvas = Canvas(width=200, height=200)
canvas.fill_style = 'blue'
canvas.fill_rect(20, 20, 100, 100)
canvas