0

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Apostolos
  • 3,115
  • 25
  • 28
  • What's qrong with my question "How can I clear an image in turtle graphics in Python?" or "How to clear an image in turtle graphics in Python?", which was my initial question. On the other hand, your "Clear an image in turtle graphics in Python?" is *not a question*. It's a statement, with an inappropriate question mark at the end. Stackoverflow prompt/button says "Ask a question" not "Post a problem" or something like that ... – Apostolos Jan 26 '18 at 12:50
  • In the same logic of yours, the question "How do I parse XML in Python?" (https://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python) should have been changed to "Parse XML in Python?", but it has not. Fortunately, madness has not striken all the place! – Apostolos Jan 26 '18 at 16:04

1 Answers1

1

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")
cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Yes, this does clear the image. Thanks. I didn't try this because I didn't think that the image is considered as a "turtle"! The command 'addshape()' refers to Screen() and not to Turtle()! Also, documentation of docs.python.org is quite deficient ... BTW, why did you changed 'ts' and 'tu' to 'screen' and 'turtle'? You like typing? :)) – Apostolos Jan 25 '18 at 08:33