Welcome to Code Sharer, a code gallery for creating, saving and sharing all kinds of code snippets.

Python — Drawing lines using Turtle in Python 3

Posted On: Saturday, August 4, 2018 at 5:07 AM Last updated: Saturday, August 4, 2018 at 5:08 AM

This is a short script shows you how to draw straight lines using the Turtle package in Python 3.

Each line is a different colour for clarity

The colours are defined using HTML colour codes.

import turtle as t

t.shape("turtle") #define the shape of the pointer - without this line of code the default would be an arrow.

t.forward(25) #move the pointer forward by 25 points
t.left(90) #turn the pointer by 90 degrees
turtle.pencolor('#FF0000') #change the color of the line over the following section to be red
t.pencolor('#32c18f') #change color to green