Skip to content

Can't clear the canvas #13

Description

@lvidarte

Hi! nice work!

I'm trying calysto turtle with ipywidgets, and I would like to clear the canvas.

How can I do that?

Here is my code

import ipywidgets as widgets
from IPython.display import display, clear_output
from calysto.graphics import *

sides  = widgets.IntSlider(min=3, max=10, description="Sides")
button = widgets.Button(description="Draw!")
canvas = Canvas(size=(400, 400))
turtle = Turtle(canvas, (200, 20), 0)

def draw_polygon(button):
    
    global sizes, canvas, turtle
    
    for _ in range(sides.value):
        turtle.forward(50)
        turtle.right(360/sides.value)
    
    clear_output(wait=True)
    display(sides, button, canvas)
        
button.on_click(draw_polygon)
display(sides, button, canvas)

If I use canvas.clear() then I get

ValueError: <Polygon [(-10, 5), (0, 0), (-10, -5), (-5, 0)]> is not in list

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions