设置海龟环境,在 Jupyter 笔记本上获取 AttributeError

我试图在 Jupyter 中运行海龟代码,但出现错误:


AttributeError: '_Screen' object has no attribute 'forward'


我能够在 PyCharm 和 Spyder 上使用相同的代码运行乌龟窗口。谁能告诉我如何设置 Jupyter 以运行海龟模块的步骤?有没有办法从 Anaconda Navigator 轻松配置乌龟和 Jupyter 的环境?


注意:PyCharm 解释器是 python,Spyder 是通过 Anaconda 安装的,解释器设置为:“默认即与 Spyder 相同”。


提前致谢。


import turtle

wn = turtle.Screen()

jack = turtle.Screen()

jack.forward(150)


宝慕林4294392
浏览 414回答 1
1回答

千巷猫影

这似乎不是环境问题。对象的forward属性不存在Screen。你的意思是这样的:import turtlewn = turtle.Screen()wn.setup(640,320)wn.bgcolor("lightblue")jack = turtle.Turtle()jack.forward(30) #move jack forward by 30turtle.done()该forward属性与Turtle类的实例一起使用。此代码适用于所有环境,包括 Jupyter Notebook。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python