繁体   English   中英

Python:“ Turtle”对象没有属性“ bye”

[英]Python: 'Turtle' object has no attribute 'bye'

我正在尝试在触发了某些内容的乌龟代码中编写乌龟代码,然后关闭了乌龟窗口,因此我尝试使用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包中的顶级功能。 它不适用于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() ,乌龟世界将以不希望重新启动的方式关闭。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM