Monday, April 21, 2025

Python Turtle - Turtle Shape, Shape Size, Pen Color, Fill Color

To set how turtle object will look, we will use shape() method. After that we can experiment with shapesize() method by passing different values as attributes:

import turtle

t = turtle.Turtle()

t.shape("arrow")
t.shapesize(10, 10, 10)


 

This is example when turtle object is circle:

import turtle

t = turtle.Turtle()

t.shape("circle")
t.shapesize(10, 10, 10)


 

This object is square:

import turtle

t = turtle.Turtle()

t.shape("square")
t.shapesize(10, 10, 10)


 

We can use triangle, too:

import turtle

t = turtle.Turtle()

t.shape("triangle")
t.shapesize(10, 10, 10)


 

And real turtle shape is created with t.shape("turtle"), if t is name of your turtle object. You can also set color for it:

import turtle

t = turtle.Turtle()

t.color("red")
t.shape("turtle")
t.shapesize(10, 10, 10)


 

Internal color is defined with fillcolor() method, and outside color with pencolor():

import turtle

t = turtle.Turtle()

t.fillcolor("red")
t.pencolor("yellow")
t.shape("turtle")
t.shapesize(10, 10, 10)


 

Animations can be done with for loops, for example:


import turtle

t = turtle.Turtle()
t.speed(1)

t.fillcolor("red")
t.pencolor("black")
t.shapesize(5, 5, 1)

for x in range(10):
    t.shape("turtle")
    t.left(90)
    t.fd(50)
    t.shape("circle")
    t.fd(70)
    t.shape("triangle")
    t.fd(100)
    t.shape("square")


Here is corresponding YouTube Tutorial for Turtle Shape, Shape Size and Pen Color.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...