在Python中清除龟图形中的图像?

时间:2018-01-23 18:18:09

标签: python turtle-graphics

我写了以下代码:

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()不会清除图像,尽管它属于tu乌龟。如果我使用ts.clear(),我会清除屏幕,即清除图形 ,但也会清除到此为止的所有事件(键和鼠标)! (我没有在这里包含事件来保持代码简单,但它们是经过测试并且工作正常的简单关键事件。)

有没有办法清除图像 - 就像图纸一样 - 没有清除事件集?

1 个答案:

答案 0 :(得分:1)

我相信你所描述的是hideturtle()。例如:

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()

取代上述turtle.hideturtle()的替代方法是:

turtle.shape("blank")