Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't clear the canvas #13

Open
lvidarte opened this issue Jul 31, 2018 · 0 comments
Open

Can't clear the canvas #13

lvidarte opened this issue Jul 31, 2018 · 0 comments

Comments

@lvidarte
Copy link

lvidarte commented Jul 31, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant