设置乌龟环境,在 Jupyter 笔记本上获取 AttributeError
setting up turtle environment, getting AttributeError on Jupyter notebooks
我尝试在 Jupyter 中 运行 海龟代码,但出现错误:
AttributeError: '_Screen' object has no attribute 'forward'
我可以在 PyCharm 和 Spyder 上使用相同的代码得到一只乌龟 window 到 运行。谁能告诉我如何设置 Jupyter 以使 turtle 模块达到 运行 的步骤?有没有办法从 Anaconda Navigator 轻松配置 turtle 和 Jupyter 的环境?
注意:PyCharm解释器是python,Spyder是通过Anaconda安装的,解释器设置为:"default ie same as Spyder's"。
提前致谢。
import turtle
wn = turtle.Screen()
jack = turtle.Screen()
jack.forward(150)
这似乎不是环境问题。 Screen
对象的 forward
属性不存在。你的意思是这样的:
import turtle
wn = turtle.Screen()
wn.setup(640,320)
wn.bgcolor("lightblue")
jack = turtle.Turtle()
jack.forward(30) #move jack forward by 30
turtle.done()
forward
属性与 Turtle
class 的实例一起使用。此代码适用于所有环境,包括 Jupyter notebook。
我尝试在 Jupyter 中 运行 海龟代码,但出现错误:
AttributeError: '_Screen' object has no attribute 'forward'
我可以在 PyCharm 和 Spyder 上使用相同的代码得到一只乌龟 window 到 运行。谁能告诉我如何设置 Jupyter 以使 turtle 模块达到 运行 的步骤?有没有办法从 Anaconda Navigator 轻松配置 turtle 和 Jupyter 的环境?
注意:PyCharm解释器是python,Spyder是通过Anaconda安装的,解释器设置为:"default ie same as Spyder's"。
提前致谢。
import turtle
wn = turtle.Screen()
jack = turtle.Screen()
jack.forward(150)
这似乎不是环境问题。 Screen
对象的 forward
属性不存在。你的意思是这样的:
import turtle
wn = turtle.Screen()
wn.setup(640,320)
wn.bgcolor("lightblue")
jack = turtle.Turtle()
jack.forward(30) #move jack forward by 30
turtle.done()
forward
属性与 Turtle
class 的实例一起使用。此代码适用于所有环境,包括 Jupyter notebook。