python - Turtle.goto 错误

标签 python typeerror turtle-graphics

当我尝试运行此 python 代码时:

import turtle
coordiantes = ['(100, 100)', '(90, 20)', '(50, 45)']
turtle.goto(coordiantes[0])

我收到此错误消息:

TypeError: new() takes 3 positional arguments but 9 were given

这是什么意思?如何修复我的代码,以便 turtle 转到列表中的一组坐标,而不为 x 和 y 值创建 2 个单独的列表?
我已经尝试删除括号,但它显示了相同的错误消息。

最佳答案

您还需要实例化您的 turtle :

bob = turtle.Turtle()

然后您可以使用 goto 但不带字符串(文档为 here ):

coordiantes = [(100, 100), (90, 20), (50, 45)]
bob.goto(*coordiantes[0])

如果您希望您的 turtle (鲍勃)遵循您在列表中提供的所有坐标,您可以使用for循环:

for i in range(len(coordinates)):
    bob.goto(*coordinates[i])

关于python - Turtle.goto 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37490057/

相关文章:

带有滚动条的 Python Turtle 窗口

mac 上的 python turtle 不工作

python - 如何在 Google App Engine 中运行脚本超过 10 分钟

python - 如何读取 Dropbox 上超过 2000 个文件的路径?

jQuery 突然停止工作

python-3.x - Python中存在数值数据时如何解决TypeError : 'No Numeric Data to Plot' ,

python - 令人困惑的类型错误

python - 如何使用 turtle 在 python 中同时绘制项目?

python - 鉴于任何纬度,长。坐标,在列表中找到最近坐标的最快方法是什么?

python - 根据日期、周、月获取平均数据