1

I am trying to write turtle code where something is triggered and the turtle window closes, so I try to use turtle.bye() but I keep getting the error:

    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'
2
  • I just installed turtle and took a quick look. turtle.bye() and turtle.Screen().bye() don't work, but I never started a mainloop. Are you sure you started a turtle mainloop()? Commented Dec 8, 2017 at 17:43
  • 1
    Can you please post your sample code? Commented Dec 8, 2017 at 17:50

1 Answer 1

2

bye() is a method of the Screen singleton instance, not Turtle. It is also mapped to a top level function in the turtle package. It will not work with a Turtle instance. You can invoke it several ways:

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()

Once you call bye() the turtle world shuts down in a manner that's not meant to be restarted.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.