Python:';海龟';对象没有属性';再见';

Python:';海龟';对象没有属性';再见';,python,turtle-graphics,Python,Turtle Graphics,我试图在触发某个事件并关闭turtle窗口的情况下编写turtle代码,因此我尝试使用turtle.bye(),但我不断收到错误: Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args) F

我试图在触发某个事件并关闭turtle窗口的情况下编写turtle代码,因此我尝试使用
turtle.bye()
,但我不断收到错误:

    Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1699, in 
__call__
    return self.func(*args)
  File "C:\Program Files\Python36\lib\turtle.py", line 686, in eventfun
    fun()
  File "E:\Home made game\Chapter 1 Log Cabin.py", line 346, in k1
    player.bye()
AttributeError: 'Turtle' object has no attribute 'bye'
bye()
是Screen单例实例的一种方法,而不是Turtle。它还映射到turtle包中的顶级函数。它不适用于海龟实例。您可以通过多种方式调用它:

import turtle

turtle.Screen().bye()  # not a turtle instance, the turtle package

turtle.bye()  # not a turtle instance, the turtle package

turtle.getscreen().bye()  # not a turtle instance, the turtle package

yertle = turtle.Turtle()
yertle.getscreen().bye()  # turtle instance gets screen singleton to invoke bye()

一旦你调用
bye()
海龟世界就会以一种不需要重新启动的方式关闭。

我刚刚安装了海龟并快速查看了一下。turtle.bye()和turtle.Screen().bye()不起作用,但我从未启动过主循环。您确定启动了turtle mainloop()?能否发布示例代码?