python - 找不到海龟命令名称
问题描述
我无法让函数调用正常工作。这是一个示例调用:
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"
我错过了什么?
解决方案
看来我必须在进行函数调用之前不断定义 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
推荐阅读
- css - Grid Container 不会占用完整的 vh
- javascript - 输入值已设置且可见,但在另一个脚本中无法访问
- powershell - 将管道参数绑定到函数参数时出现空错误
- scala - Scala 函数式编程和可变性
- visual-studio-code - vsCode 设置和切换编程语言
- python-3.x - tensorflow show ImportError: DLL load failed: %1 is not an valid Win32 application
- mysql - 另一个无法在 gcloud 中远程 mysql
- c# - Bot Framework 在对话之外读取 UserState 数据或恢复对话对话
- r - 如何通过 R 中的 For 循环创建许多线性回归模型?
- google-sheets - 如何从 X 单元格中获取最后 2 个数字并将它们添加到 Y 单元格中的 @ 之前?