【发布时间】:2014-03-08 22:03:01
【问题描述】:
重要提示我没有注意到有两个不同的地方我必须将设置从 Qt4 更改为 SVG。我把它们都改了,“没有找到海龟”的问题就解决了。我需要感谢 Jonathan March,他通过他建议的链接将我引向了正确的方向。
问题解决了!!
我在 MacBook Pro 64 位操作系统 10.9.2 上使用 Canopy 1.3.0.1715(32 位)。
当我尝试使用时
from turtle import Turtle
天篷说
name 'Turtle' is not defined
这是我的代码,名为 draw.py(我想画一个正方形):
from turtle import Turtle
t = Turtle()
def drawsquare(t, x, y, side):
t.up()
t.goto(x,y)
t.setheading(270)
t.down()
for count in range(4):
t.forward(side)
t.left(90)
我也像这样创建了一个文件turtle.cfg
width = 300
height = 200
using_IDLE = True
colormode = 255
请尽可能简单,我最近才开始使用 Python。谢谢大家。
【问题讨论】:
-
你能解释一下你的海龟是什么吗?
-
你可以试试 t = turtle() 而不是大写的 T
-
在运行此代码的同一文件夹中是否有一个名为“turtle.py”的文件?
-
正如我正在学习的书所说(Python 基础:第一个程序)我创建了一个文件 turtle.cfg(阅读上文)
-
如果我尝试 t = turtle() Canopy 仍然显示
name 'Turtle' is not defined
标签: python macos turtle-graphics canopy