Shell-o world: Turtle graphics in Python

No readers like this yet.
Open source code for a better food system, code with grass image

Photo by Jen Wike Huger

Turtle graphics is a popular way to introduce young learners to programing. It was part of the original Logo programming language, which, according to Wikipedia, is an educational programming language Seymour Papert and others designed in 1967.

I first encountered Logo as a graduate student in education. As a young adult, I'd struggled with mathematics. Abstract concepts—which others so easily grasped—evaded my understanding, and mathematics became anathema to me. That changed in graduate school, when my assignment was to teach a fifth grade student geometry using a special curriculum that used Logo and Turtle graphics.

One of my teacher colleagues recently shared his strategies for using Turtle graphics with Python. This piqued my interest (due to my earlier experiences). Since Python is included with most Linux distributions, I was eager to meet my old friend the Turtle.

To begin, I needed to install Python's graphical interface, Tkinter. Once I accomplished that, I was ready to begin. I opened a terminal, typed "python," and pressed Enter.

At the Python prompt, I typed "import turtle"—and was ready to begin. At the prompt, I typed, "turtle.forward(100)" and pressed Enter. The graphical interface appeared, and the turtle moved 100 turtle steps forward.

You can use many commands to turn, change the pen color, pick up the pen, change the background color, and more. The Python documentation is very good.

Turtle screenshot

Turtle's real power, however, lies not in its ability to simply execute commands, but its promise for encouraging students to think procedurally and reflect on their thinking. Using Turtle graphics, it's possible for programming students to get immediate visual feedback from their programming and to explore mathematical concepts, including estimation and variability, at the same time. Using a text editor like Gedit or Vi, it's possible to create a simple program for drawing a hexagon, for example. Using the reference materials provided at the Python site and a text editor, I created program to draw a square and executed it.

import turtle turtle.forward(90) turtle.rt(90) turtle.forward(90) turtle.rt(90) turtle.forward(90) turtle.rt(90) turtle.forward(90) turtle.rt(90) turtle.done()

You can accomplish more complex programming operations, too. I saved this simple program as "square.py," then executed it with Python. Here is an example of some more complex scripts by a young programmer I found on the Internet. And here's a YouTube example of a complex design created with a very simple script.

You can easily see that Python Turtle graphics are another example of open source's power to provide a world-class programming environment that is extremely affordable.

User profile image.
Educator, entrepreneur, open source advocate, life long learner, Python teacher. M.A. in Educational Psychology, M.S. Ed. in Educational Leadership, Linux system administrator.

5 Comments

LOGO has been a built in feature in LibreOffice since many years.

Select "View" - "Toolbars" - "Logo".

...and you are ready to go!

Cheers,
Leif

Despite being part of core LibreOffice now, it's not installed by default in every distribution.

$ sudo dnf install libreoffice-librelogo -y

... did the trick for me. By the way, to specify, this in in LibreOffice Writer.

Great tip! Thanks!

In reply to by Leif Lodahl (not verified)

Thanks for pointing that out. I had no idea it was part of LibreOffice. That's very interesting.

In reply to by Leif Lodahl (not verified)

how to install python in windows !!

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.