A MultiCanvas
allows you to have multiple canvases one on top of the other. This is very useful when you need multiple layers that don't have the same update frequency (e.g. if you make a Tetris game you might only want to render the background image once, and never draw it again).
from ipycanvas import MultiCanvas
m = MultiCanvas(n_canvases=3, width=200, height=200)
m
def draw_square(canvas, pos, width, color):
canvas.fill_style = color
canvas.fill_rect(pos, pos, width, width)
draw_square(m[0], 0, 200, 'orange')
draw_square(m[1], 50, 100, 'blue')
draw_square(m[2], 75, 50, 'green')
draw_square(m[0], 0, 200, 'red')
m[1].clear()
draw_square(m[0], 0, 200, 'orange')