close

How to change size of turtle?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to change size of turtle in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to change size of turtle?

  1. How to change size of turtle?

    The default size of a Turtle object is 20 pixels, which is the equivalent of the ratio 1 when resizing the Turtle.

  2. change size of turtle

    The default size of a Turtle object is 20 pixels, which is the equivalent of the ratio 1 when resizing the Turtle.

Method 1

Change this line:

tess.turtlesize(increase)

to instead be:

tess.turtlesize(*increase)

turtlesize() wants three separate values but you were passing one tuple of three values so we need to spread that tuple across the argument list.

Method 2

The default size of a Turtle object is 20 pixels, which is the equivalent of the ratio 1 when resizing the Turtle.

For example:

import turtle

tess = turtle.Turtle()
print(tess.shapesize())

Output:

(1.0, 1.0, 1)

The first two 1.0s in the tuple represents how many units 20 pixels the Turtle‘s width and height are, and the last 1 represents the width of the Turtle‘s outline. You won’t be able to see the outline if you only pass one argument into the tess.color() brackets, because by default, there is no outline.

To increase the Turtle‘s size, simply pass in the number of 20 pixels you want each of the Turtle‘s dimensions to be into tess.shapesize() or tess.turtesize():

import turtle

tess = turtle.Turtle()
tess.shapesize(2, 3, 1) # Sets the turtle's width to 60px and height to 90px

The other answer points out that the turtlesize function does not take in an array; it takes in ints or floats, so you’ll need to unpack the tuple with a * when you pass the tuple into the function.

In your increaseSize function, the tuple and [] wrappers aren’t necessary, and only wastes efficiency. Simply use ():

def increaseSize():
    size = tess.turtlesize()
    increase = (2 * num for num in size)
    tess.turtlesize(*increase)

On top of your code there is

turtle.setup(500,500)
wn = turtle.Screen()

Since you defined a Screen object, wn, it’s cleaner to use wn.setup() instead of turtle.setup():

wn = turtle.Screen()
wn.setup(500,500)

All together:

import turtle

wn = turtle.Screen()
wn.setup(500,500)

tess = turtle.Turtle("triangle")
tess.color("red")
tess.left(90)

def increaseSize():
    size = tess.turtlesize()
    increase = (2 * num for num in size)
    tess.turtlesize(*increase)

wn.onkey(increaseSize, "x")
wn.listen()

Output:

enter image description here

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read