2

I was following the first few lines of instructions here, https://docs.python.org/3.4/library/turtle.html, which lead to this masterpiece:

import turtle
turtle.forward(15)

However, after the Python turtle graphics window appears (with the little arrow in the middle), the kernel dies instantly. What do I need to add?

I saw a video where t=turtle.pen() is added, but it leads to the same result.

355durch113
  • 201
  • 2
  • 8
  • One needs to add turtle.Turtle() – 355durch113 Oct 16 '15 at 04:33
  • I wrote a turtle module for the notebook called [mobilechelonian](https://pypi.python.org/pypi/mobilechelonian). If you can install that, you should be able to use it like the standard turtle module. – Thomas K Oct 16 '15 at 10:38
  • @ThomasK I will try it out, thank you! Another possibility I found is to also import the tkinter module, and add `done()` at the end. – 355durch113 Oct 16 '15 at 21:53
  • I tested your two lines in *IDLE3*, as well as plain *python3* prompt under Ubuntu, and it works... `turtle.forward(15)` opened a window and created a turtle, and then moved it forward 15 pixels. Please add as detailed information about "the kernel dies instantly" as you can. Like, is there error message? Can you get one? – hyde Oct 17 '15 at 07:00
  • Following this [other question](https://stackoverflow.com/questions/56581957/turtle-does-not-run-more-than-once-in-jupyter-notebook/57707785#57707785), you can find a solution using ipyturtle. – MordicusEtCubitus Aug 29 '19 at 11:47

1 Answers1

2

I tested your two lines in IDLE3, as well as plain python3 prompt under Ubuntu, and it works... turtle.forward(15) opened a window and created a turtle, and then moved it forward 15 pixels.

To help you figure it out, here is an interactive session I run, which does things in more steps. Perhaps that will work for you (in that case you have encountered a bug in your version of Python or the turtle graphics), and if not, at least you will know where exactly "the kernel dies" (whatever you mean by that, exactly).

$ python3
Python 3.4.3 (default, Jul 28 2015, 18:24:59) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> win = turtle.Screen()
>>> t = turtle.Turtle()
>>> t.fd(15)
>>> 
hyde
  • 60,639
  • 21
  • 115
  • 176
  • Maybe I needed to say that all of this happens in an IPython 3.4 notebook *and* Windows 10; however, I solved the problem by adding `done()` at the end, otherwise, the turtle *does* go 15 pixels, but the window gets blurred out and the red "dead kernel" field appears in the upper right corner. Thereafter it restarts and I need to remove the turtle.Screen() via Task Manager. Seems to be related to [this](http://stackoverflow.com/questions/6234798/python-turtle-graphics-how-do-i-control-when-the-window-closes). – 355durch113 Oct 17 '15 at 18:36