turtle.turtlesize() function in Python

The turtle.turtlesize() function sets the size of the turtle. Can stretch the turtle’s width and length, and set its outline width independently.

Syntax: turtle.turtlesize(stretch_wid=None, stretch_len=None, outline=None)
Parameters: stretch_wid – stretch factor perpendicular to orientation; stretch_len – stretch factor parallel to orientation; outline – width of the shape’s outline.

Let us see an example to implement the turtle.turtlesize() function in Python:

Demo42.py

# turtle.turtlesize() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.turtlesize(1, 1)      # Normal size (stretch_width, stretch_length)
t.forward(50)
t.turtlesize(2, 3)      # Make turtle wider and longer
t.forward(50)
t.turtlesize(1, 1, 2)   # Normal size, outline width 2

window.exitonclick()

The following is the output:

turtle.turtlesize() function in Python

In the above code, we followed the below steps:

  • import turtle – Loads the turtle graphics module.
  • window = turtle.Screen() – Creates the drawing window.
  • t = turtle.Turtle() – Initializes the turtle object.
  • t.turtlesize(1, 1) – Sets the turtle to its normal size: stretch width = 1, stretch length = 1.
  • t.forward(50) – Moves the turtle forward 50 units with default size.
  • t.turtlesize(2, 3) – Stretches the turtle: width doubled, length tripled.
  • t.forward(50) – Moves forward 50 units with the new stretched shape.
  • t.turtlesize(1, 1, 2) – Resets to normal size but sets outline thickness to 2 pixels.
  • window.exitonclick() – Keeps the window open until clicked, then closes.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.shape() function in Python
turtle.tilt() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment