【问题标题】:simple turtle module code python 3.9.7 problem简单的turtle模块代码python 3.9.7问题
【发布时间】:2021-09-24 14:58:03
【问题描述】:

我正在测试 turtle 模块,但命令不起作用。我在 Windows 10 上并下载了 python 3.9.7 这是代码:

>>> import turtle
>>> t = turtle.pen()
>>> t.forward(50)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    t.forward(50)
AttributeError: 'dict' object has no attribute 'forward'
>>> 

此代码打开带有海龟显示的第二个窗口,但它不向前移动并显示错误。有谁知道我该如何解决这个问题?提前致谢。

【问题讨论】:

  • 这是大小写错误,应该是:t = turtle.Pen() 大写的Pen()Turtle() 的别名,而小写的pen() 函数则完全不同。

标签: python turtle-graphics python-turtle


【解决方案1】:

正确的语法是:

import turtle
t = turtle.Turtle() # create a Turtle and assign it to the variable "t"
t.forward(50)

【讨论】:

    猜你喜欢
    • 2020-02-05
    • 2012-02-13
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多