0

I have a small program where I would like to pop up a Python turtle window, display something, close on user click, then pop up a next window. An example program for this is

import turtle

window = turtle.Screen()
t1 = turtle.Turtle()
t1.forward(100)
window.exitonclick()

window2 = turtle.Screen()
t2 = turtle.Turtle()
t2.forward(100)
window2.exitonclick()

The program crashes when trying to open the second window. This is with Python3.6 on a Mac OS X machine. I have seen some reference to crashes when re-running a program twice, and seen advice about adding a bye() call after the first window close, but I haven't managed to work around this yet.

Any suggestions?

1 Answer 1

0

It seems like you should probably using a different function then exitonclick to exit out of the screen or clear it. But I was able to get your code working by running turtle.bye() and doing a try/except around it in case of errors.
It's definitely not an elegant solution but is a workaround to get the second window to appear properly.

import turtle

window = turtle.Screen()
t1 = turtle.Turtle()
t1.forward(100)
window.exitonclick()

try:
    turtle.bye()
except Exception:
    pass

window2 = turtle.Screen()
t2 = turtle.Turtle()
t2.forward(100)
window2.exitonclick()

Not the answer you're looking for? Browse other questions tagged or ask your own question.