📜  Python – turtle.clear()

📅  最后修改于: 2022-05-13 01:55:26.009000             🧑  作者: Mango

Python – turtle.clear()

turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。

海龟.clear()

此函数用于从屏幕上删除海龟的绘图。不移动海龟的状态和位置以及其他海龟的绘图不受影响。它不需要任何论据。

以下是上述方法的实现以及一些示例:

示例 1:

# import package
import turtle
  
# motion
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
  
# clear the drawing
# and remain turtle 
# as it is
turtle.clear()

输出 :

示例 2:

# import package
import turtle
  
# make a turtle object
# and do some drawing
t1 = turtle.Turtle()
t1.up()
t1.setpos(-100, 50)
t1.down()
t1.circle(50)
  
# make a turtle object
# and do some drawing
t2 = turtle.Turtle()
t2.up()
t2.setpos(50, 50)
t2.down()
t2.circle(50)
  
# make a turtle object
# and do some drawing
t3 = turtle.Turtle()
t3.up()
t3.setpos(50, -100)
t3.down()
t3.circle(50)
  
# make a turtle object
# and do some drawing
t4 = turtle.Turtle()
t4.up()
t4.setpos(-100, -100)
t4.down()
t4.circle(50)
  
# here we clear the work done by turtle 
# objects : t1 and t3 only but turtle 
# shape remain as it is
t1.clear()
t3.clear()

输出 :