python-3.x Turtle窗口不关闭,即使有2行代码也显示错误“终止符“

mnemlml8  于 2022-11-26  发布在  Python
关注(0)|答案(1)|浏览(241)

我正在学习Python中的OOP,具体来说是关于turtle模块的。写了这个代码,运行它显示错误“终结者“...希望它不是天网
第一个
turtle graphics window which doesn't close
If i re-run the program it runs fine

from turtle import Turtle,Screen

timmy = Turtle()
print(timmy)
timmy.shape("turtle")
timmy.color("blue")

timmy.forward(100)
my_screen = Screen()
my_screen.bgcolor("coral")
my_screen.exitonclick()

错误消息:

Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
Terminator                                Traceback (most recent call last)
Untitled-1.ipynb Cell 1 in <cell line: 4>()
      1 from turtle import Turtle,Screen
----> 4 timmy = Turtle()
      5 print(timmy)
      6 timmy.shape("turtle")

File ~/anaconda3/lib/python3.9/turtle.py:3815, in Turtle.__init__(self, shape, undobuffersize, visible)
   3813 if Turtle._screen is None:
   3814     Turtle._screen = Screen()
-> 3815 RawTurtle.__init__(self, Turtle._screen,
   3816                    shape=shape,
   3817                    undobuffersize=undobuffersize,
   3818                    visible=visible)

File ~/anaconda3/lib/python3.9/turtle.py:2558, in RawTurtle.__init__(self, canvas, shape, undobuffersize, visible)
   2556 self._undobuffersize = undobuffersize
   2557 self.undobuffer = Tbuffer(undobuffersize)
-> 2558 self._update()

File ~/anaconda3/lib/python3.9/turtle.py:2661, in RawTurtle._update(self)
   2659     return
   2660 elif screen._tracing == 1:
-> 2661     self._update_data()
...
-> 1293     raise Terminator
   1294 if self._tracing > 0:
   1295     self._updatecounter += 1

Terminator:

再次重新运行可获得所需的输出

ecr0jaav

ecr0jaav1#

你的代码没有错,尽管我可能用不同的方式表达:

from turtle import Turtle, Screen

my_screen = Screen()
my_screen.bgcolor("coral")

timmy = Turtle()
timmy.shape("turtle")
timmy.color("blue")

timmy.forward(100)

my_screen.exitonclick()

你需要在你的代码之外寻找问题。在这个例子中,是Anaconda环境。在那个环境之外尝试一下,让自己相信代码是有效的。
根据Anaconda尝试重新运行它的方式,可能会出现Terminator错误,因为一旦turtle环境在exitonclick()之后关闭,它就无法重新启动。程序必须在一个干净的映像中重新运行。

相关问题