【发布时间】:2019-10-28 03:13:09
【问题描述】:
我正在尝试在 jupyter notebook 中运行一些海龟代码。当我运行一次代码时,代码运行良好。但是,如果我再次运行代码,Python Turtle Graphics 会冻结并关闭(又名 python turtle 图形没有响应)并且 jupyter notebook 的内核崩溃
我尝试过切换笔记本,重新安装 jupyter 并重新启动内核,但都没有成功。
这是海龟代码:
import turtle
pen = turtle.Pen()
window = turtle.Screen()
pen.color("light blue")
pen.shape("turtle")
pen.forward(100)
window.exitonclick()
这是我第二次运行代码时的错误消息。笔记本保存在C:\Users\fligh\OneDrive\Jupyter Notebooks\,文件名为“Principles 2 Playground”:
<ipython-input-2-79042881c88e> in <module>
1 import turtle
----> 2 pen = turtle.Pen()
3 window = turtle.Screen()
4 pen.color("light blue")
5 pen.shape("turtle")
c:\users\fligh\appdata\local\programs\python\python37-32\lib\turtle.py in __init__(self, shape, undobuffersize, visible)
3814 shape=shape,
3815 undobuffersize=undobuffersize,
-> 3816 visible=visible)
3817
3818 Pen = Turtle
c:\users\fligh\appdata\local\programs\python\python37-32\lib\turtle.py in __init__(self, canvas, shape, undobuffersize, visible)
2555 self._undobuffersize = undobuffersize
2556 self.undobuffer = Tbuffer(undobuffersize)
-> 2557 self._update()
2558
2559 def reset(self):
c:\users\fligh\appdata\local\programs\python\python37-32\lib\turtle.py in _update(self)
2658 return
2659 elif screen._tracing == 1:
-> 2660 self._update_data()
2661 self._drawturtle()
2662 screen._update() # TurtleScreenBase
c:\users\fligh\appdata\local\programs\python\python37-32\lib\turtle.py in _update_data(self)
2644
2645 def _update_data(self):
-> 2646 self.screen._incrementudc()
2647 if self.screen._updatecounter != 0:
2648 return
c:\users\fligh\appdata\local\programs\python\python37-32\lib\turtle.py in _incrementudc(self)
1290 if not TurtleScreen._RUNNING:
1291 TurtleScreen._RUNNING = True
-> 1292 raise Terminator
1293 if self._tracing > 0:
1294 self._updatecounter += 1
Terminator:
有人可以帮助我吗? 谢谢
【问题讨论】:
标签: python jupyter-notebook turtle-graphics