我在调用函数时遇到问题。这是一个示例调用: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"我错过了什么?
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
似乎我必须在进行函数调用之前不断定义 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
添加回答
举报
0/150
提交
取消