问题
This simple Python script:
import turtle
bob = turtle.Turtle()
bob.forward(50)
turtle.done()
yields an error when running it using Spyder. The first run works as expected, but after that, the IPython console raises a "Terminator". The same happens when using turtle.exitonclick()
instead of turtle.done()
. What am I doing wrong?
Note that running it from the CLI works fine.
回答1:
I don't use Spyder but have exchanged comments with others who have similar problems running turtle in similar environments.
If you close the turtle graphics window, it's dead and won't reopen for you. Short of restarting Spyder, you can try adding a turtle.bye()
(which cleans up some things) after turtle.done()
(which returns after the main loop exits). Then try running your program multiple times.
回答2:
I was having trouble running a turtle graphics program more than once in Spyder, and I solved it by going to "Tools / Preferences". In the "Run" section, under "Console", select "Execute in a new dedicated Python console".
来源:https://stackoverflow.com/questions/43294665/turtle-done-not-working-in-spyder