spyder: Problems with running turtle programs in Spyder

Description

when i try to launch a script using turtle the turtle graphics window is not working. What steps will reproduce the problem?

  1. write a script like:
import turtle

wn=turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle() # Create tess and set some attributes
tess.color("hotpink")
tess.pensize(5)
alex = turtle.Turtle() # Create alex

tess.forward(80) # Make tess draw equilateral triangle
tess.left(120)
tess.forward(80)
tess.left(120)
tess.forward(80)
tess.left(120) # Complete the triangle

turtle.done()
  1. launch it

What is the expected output? What do you see instead? The graphic window opens up but it doesn’t produce the output because it stops saying it is not working

Version and main components

  • Spyder Version: 3.2.4
  • Python Version: 3.6.3
  • Qt Versions: 5.6.2, PyQt5 5.6 on Windows

Dependencies

pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.4 (OK)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 33 (20 by maintainers)

Most upvoted comments

@ccordoba12 testing a little bit with Turtle I came with some tips to run a script multiple times in Spyder or prevent the crash of the IPython kernel when trying to run a script that uses Turtle (at least on Windows):

  1. Call turtle.done() with turtle.bye() and use the Inline or Automatic backend for the IPython Console (Preferences > IPython Console > Graphics > Graphics Backend). As an example:
import turtle

wn=turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle() # Create tess and set some attributes
tess.color("hotpink")
tess.pensize(5)
alex = turtle.Turtle() # Create alex

tess.forward(80) # Make tess draw equilateral triangle
tess.left(120)
tess.forward(80)
tess.left(120)
tess.forward(80)
tess.left(120) # Complete the triangle

alex = turtle.forward(100)

turtle.done()
turtle.bye()   

The call of turtle.bye() will raise a Terminator error but the IPython kernel will not die. To prevent the output of the exception you can use a try-except:

...
turtle.done()
try:
    turtle.bye()   
except turtle.Terminator:
    pass

The reason for this is to clean some elements used by Turtle after running.

  1. Instead of using the IPython Console you can use an external system terminal. Go to Run > Configuration per file... > Select Execute in an external system terminal over the Console section.

I really don’t know what happens and we don’t have time to help you debug it, sorry.

Great, thanks @dalthviz! It looks really good, I only made a couple of minor modifications to it.

Great job @dalthviz ! Your writing looks very good to me.

I know this is closed because of lack of resources to address. I’m adding the following for informational purposes.

Turtle graphics are a useful tool for visualizing L-Systems and fractals, as described in “The Algorithmic Beauty of Plants”. I find it a very useful educational and visualization tool for some things. Everything works great in Linux. Unfortunately, for teaching purposes, I’m force to use a Windows computer. The module appears to work fine, as long as I don’t click on the turtle window itself. When I click on the turtle window, it crashes and takes the python kernel down with it.

This is a python 3 anaconda installation of spyder