Table of Contents
In this Python tutorial, we will cover the basic features and commands of Python Turtle. The Python Turtle graphics is a fun way to learn the basic of programming, especially kids and beginners. If order to learn how to program using Python Turtle, you should understand why one would want to program or draw using Python Turtle.
What is Python Turtle?
The Python Turtle module is a feature in Python that draws and let’s you control and command the turtle. The turtle moves around with commands such as turtle.forward(), turtle.backward(), turtle.left() and turtle.right(). Imagine having a turtle that was robotic and started in x-y plane (0-0). We could then use the turtle.forward(10) command and it will move on the screen 10 pixels. Now what if we use the command turtle.left(20)? This command would make the turtle rotate 20 degrees clockwise in place.
Python Turtle Commands
The below basic commands are enough to get started and work around some creating fun and innovative designs in turtle.
Python Turtle Graphics Module Download
Before we can start to have fun and program with the Python turtle module, we must import the module first.
Input:
import turtle
Build Your First Design in Python Turtle
Below is some simple code to build your first design in Python turtle. It’s nothing fancy, but the purpose of this is to break down the code and learn what it does. First of all, you should know what a while loop is in Python and understand how the loop breaks once it meets a certain criteria.
Input:
from turtle import * color('green', 'black') begin_fill() while True: forward(80) left(60) if abs(pos()) < 1: break end_fill()
Output:
Another Python Turtle Design
Below is another Python turtle design with a few changes in color, forward and left numerical values.
Input:
from turtle import * color('blue', 'purple') begin_fill() while True: forward(300) left(500) if abs(pos()) < 1: break end_fill() done()
Output:
I hope this Python tutorial on Python Turtle was helpful and informative.