question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with running turtle programs in Spyder

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:33 (20 by maintainers)

github_iconTop GitHub Comments

5reactions
dalthvizcommented, Feb 17, 2019

@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.
2reactions
ccordoba12commented, Jan 24, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turtle Graphics Not Responding - python - Stack Overflow
I'm using python 3.6.0 and ran into the same issue. The turtle.done() after your code block prevents the turtle graphic window from becoming...
Read more >
Turtle Programming in Python - GeeksforGeeks
Turtle Programming in Python · Import the turtle module · Create a turtle to control. · Draw around using the turtle methods. ·...
Read more >
5.9. ‍ Common turtle Errors - Runestone Academy
Below we'll describe common errors that beginning programmers encounter when writing turtle code. Some of these errors can be applied to other instances...
Read more >
3. Hello, little turtles! — How to Think Like a Computer Scientist
Let's write a couple of lines of Python program to create a new turtle and start ... a turtle script in Spyder, make...
Read more >
What is Python Turtle used for? - Educative.io
turtle is a pre-installed Python library that allows users to create pictures ... When we run these commands, the turtle will turn right...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found