9voltWolfXX
9voltWolfXX

Reputation: 143

Python Turtle shows blank screen when running code

I've begun to experiment with turtle on Python 3.5, and I've encountered an odd error. My code is:

 import turtle                    
 wn = turtle.Screen()             
 bob = turtle.Turtle()      
 bob.forward(150)               
 bob.left(90)               
 bob.forward(75)            

Oddly enough, when I first ran this, it worked perfectly, but now every time it shows a blank turtle screen. When I run this line-by-line, I get to this error message from line 3:

Traceback (most recent call last):

File "pyshell#2", line 1, in bob = turtle.Turtle()

File "/usr/lib/python3.5/turtle.py", line 3816, in init visible=visible)

File "/usr/lib/python3.5/turtle.py", line 2557, in init self._update()

File "/usr/lib/python3.5/turtle.py", line 2660, in _update self._update_data()

File "/usr/lib/python3.5/turtle.py", line 2646, in _update_data self.screen._incrementudc()

File "/usr/lib/python3.5/turtle.py", line 1292, in _incrementudc

raise Terminator

turtle.Terminator

If I try and call bob after this, the shell tells me it is not defined... Any help appreciated!

Upvotes: 0

Views: 2451

Answers (3)

Shahid Ghafoor
Shahid Ghafoor

Reputation: 1059

if you are using macOS, try installing python-tk by using this command:

  brew install python-tk

Upvotes: 1

Andrew
Andrew

Reputation: 113

I encountered same issue with Turtle graphics and PythonWin. On second run the screen is displayed but script hangs when new turtle class is instanced. But when I run it with IDLE, the script can be ran over and over.

Upvotes: 0

cdlane
cdlane

Reputation: 41925

Here's my guess: I believe the error you're triggering is this:

   if not TurtleScreen._RUNNING:
        TurtleScreen._RUNNING = True
        raise Terminator

I'm assuming you're not running a file but instead pasting commands into an interpreter -- which is fine. But if you close the turtle graphics window, it won't reopen for you. You can try restarting your interpreter anew, or you might try doing a turtle.bye() and then running your commands again -- sometimes it works to reopen the window, sometimes it doesn't.

Upvotes: 1

Related Questions