我无法使函数调用正常工作。这是一个示例调用:
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)
我已经导入了龟,但是出现以下错误:
TclError: invalid command name ".!canvas"
我想念什么?
答案 0 :(得分:0)
似乎我必须在进行函数调用之前连续定义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