找不到 Turtle 命令名称
Turtle command name not found
我在调用函数时遇到问题。这是一个示例调用:
def polyline(t,n,length,angle):
"""Draws n line segments with the given length and
angle(in degrees) between them. t is a turtle.
"""
for i in range(n):
t.fd(length)
t.lt(angle)
关联的调用是这样的
alex=turtle.Turtle()
polyline(alex,5,100,90)
我已经导入了 turtle,但出现以下错误:
TclError: invalid command name ".!canvas"
我错过了什么?
看来我必须在调用函数之前不断地定义alex。例如这有效:
def polyline(t,n,length,angle):
"""Draws n line segments with the given length and
angle(in degrees) between them. t is a turtle.
"""
for i in range(n):
t.fd(length)
t.lt(angle)
alex=turtle.Turtle()
#Test polyline
polyline(alex,5,780,90)
这失败了:
alex=turtle.Turtle()
#insert some other functions
#define polyline function
#call polyline
我在调用函数时遇到问题。这是一个示例调用:
def polyline(t,n,length,angle):
"""Draws n line segments with the given length and
angle(in degrees) between them. t is a turtle.
"""
for i in range(n):
t.fd(length)
t.lt(angle)
关联的调用是这样的
alex=turtle.Turtle()
polyline(alex,5,100,90)
我已经导入了 turtle,但出现以下错误:
TclError: invalid command name ".!canvas"
我错过了什么?
看来我必须在调用函数之前不断地定义alex。例如这有效:
def polyline(t,n,length,angle):
"""Draws n line segments with the given length and
angle(in degrees) between them. t is a turtle.
"""
for i in range(n):
t.fd(length)
t.lt(angle)
alex=turtle.Turtle()
#Test polyline
polyline(alex,5,780,90)
这失败了:
alex=turtle.Turtle()
#insert some other functions
#define polyline function
#call polyline