【问题标题】:turtle showing error which used to work fine earlier乌龟显示错误,以前可以正常工作
【发布时间】:2021-01-16 13:41:21
【问题描述】:
import turtle
t = turtle.Turtle()
t.forward(100)
t.done()
  1. 此代码返回如下错误 NameError: name 'turtle' 未定义
  2. 我尝试使用 turtle,但它似乎不像代码中显示的那样工作。
  3. 我尝试参考各种来源,但找不到修复方法

【问题讨论】:

  • 我看不出您提供的代码如何引发该错误。请提供minimal reproducible example 以及您在运行它时获得的实际回溯。
  • 尝试使用以下命令运行一些演示脚本:$. python -m turtledemo.bytedesign 如果你得到一个回溯然后 python 不能访问 turle 出于某种原因。

标签: python python-3.x turtle-graphics python-turtle


【解决方案1】:

问题出在这一行:

t.done()

您看,您将t 定义为Turtle object,而Turtle 对象没有done 属性。

done() 属性属于turtle 模块本身,所以不是t.done(),而是turtle.done()

import turtle
t = turtle.Turtle()
t.forward(100)
turtle.done()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多