turtle.width() function in Python (original) (raw)

Last Updated : 29 Aug, 2025

This method set or return the line thickness. Set the line thickness to width or return it. If resizemode is set to "auto" and turtleshape is a polygon, that polygon is drawn with the same line thickness. If no argument is given, the current pensize is returned.

**Syntax :

tturtle.width(width=None)

# or

turtle.pensize(width=None)

**Parameters : width -> Positive number specifying the thickness of the line. Optional; if omitted, the current width is returned.

**Returns:

Examples

**Example 1 : Setting a fixed line width

Python `

import turtle turtle.forward(100) turtle.width(4)

turtle.right(90) turtle.forward(100)

`

**Output :

**Explanation: The turtle first draws a line with the default width (usually 1). After setting **turtle.width(4), the next line is drawn thicker, with a width of 4.

**Example 2 : Changing line width dynamically in a loop

Python `

import turtle for i in range(15):

turtle.width(15-i) turtle.forward(50+15*i) turtle.right(90)

`