turtle.done() not working in Spyder

寵の児 提交于 2019-12-11 06:36:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!