1
import turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape('classic')
brad.color('yellow','green')
brad.speed(2)
for i in range(4):
brad.forward(100)
brad.right(90)
brad.circle(-50)
for i in range(3):
brad.forward(100)
brad.right(120)
window.exitonclick()
2
import turtle
def draw_square(some_turtle):
for i in range(4):
some_turtle.forward(100)
some_turtle.right(90)
def draw_art():
window = turtle.Screen()
window.bgcolor('red')
brad = turtle.Turtle()
brad.shape('turtle')
brad.color('yellow')
brad.speed('fast')
for i in range(37):
draw_square(brad)
brad.right(10)
3
window = turtle.Screen() 调用turtle.Screen类,产生一个窗口
# 画一个圆形
angie = turtle.Turtle()
angie.shape('arrow')
angie.color('blue')
angie.circle(-50)
window.exitonclick() # window其实是类turtle.Screen, 这里调用了类里的一个函数:单击退出