Apostolos
Apostolos

Reputation: 3477

Clear an image from turtle graphics in Python?

I wrote the following code:

from turtle import *

ts = Screen(); tu = Turtle()
image = "apple.gif"
ts.addshape(image)
tu.shape(image)    # The image is displayed
sleep(2); tu.clear # This doesn't clear the image 
done()

tu.clear() doesn't clear the image, although it it belongs to tu turtle. If I use ts.clear(), I clear the screen, i.e. the graphics are cleared, but also all events up to this point (key and mouse) are cleared! (I have not included the events here to keep the code simple, but they are simple key events that have been tested and work fine.)

Is there a way to clear an image -- as one does with drawings -- w/o also clearing events set?

Upvotes: 0

Views: 2064

Answers (1)

cdlane
cdlane

Reputation: 41925

I believe what you're describing is hideturtle(). For example:

from time import sleep
from turtle import Turtle, Screen

IMAGE = "apple.gif"

screen = Screen()
screen.addshape(IMAGE)

turtle = Turtle()
turtle.shape(IMAGE)  # The image is displayed

sleep(2)

turtle.hideturtle()
screen.exitonclick()

An alternative approach in place of turtle.hideturtle() above is:

turtle.shape("blank")

Upvotes: 1

Related Questions