我有一个问题,我正在尝试使用turtle模块在Python(2.7)中绘制一个正方形和一个圆形。
import turtle
def draw_cricle(circle_size):
boby = turtle.Turtle()
boby.color("black")
boby.shape("arrow")
boby.right(90)
boby.forward(200)
boby.left(90)
boby.back(20)
boby.circle(circle_size)
def draw_square(forward_dst, right_angle):
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("circle")
brad.speed(3)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
window.exitonclick()
draw_square(100,90)
draw_cricle(100)
我的问题是调用draw_square函数后无法调用draw_circle函数。
是的,我知道我应该在draw_square中使用循环
答案 0 :(得分:0)
从draw_square
函数运行window.exitonclick()时,您正在关闭窗口。如果要使用同一窗口绘制正方形和圆形,则应在这些函数之外定义窗口,否则,在开始绘制圆形之前,您将关闭该窗口。
import turtle
def draw_cricle(circle_size):
boby = turtle.Turtle()
boby.color("black")
boby.shape("arrow")
boby.right(90)
boby.forward(200)
boby.left(90)
boby.back(20)
boby.circle(circle_size)
def draw_square(forward_dst, right_angle):
brad = turtle.Turtle()
brad.shape("circle")
brad.speed(3)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
brad.forward(forward_dst)
brad.right(right_angle)
window = turtle.Screen()
window.bgcolor("red")
draw_square(100,90)
draw_cricle(100)
window.exitonclick()