turtle.width() function in Python
Last Updated :
20 Jul, 2020
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.width()
This method is used to 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 :
turtle.width(width=None)
turtle.pensize(width=None)
Note: This method has Aliases: pensize and width and requires only one argument “width — positive number”.
Below is the implementation of the above method with some examples :
Example 1 :
Python3
import turtle
turtle.forward( 100 )
turtle.width( 4 )
turtle.right( 90 )
turtle.forward( 100 )
|
Output :
Example 2 :
Python3
import turtle
for i in range ( 15 ):
turtle.width( 15 - i)
turtle.forward( 50 + 15 * i)
turtle.right( 90 )
|
Output :
In this above example, we decrease the size of the turtle at every move so the size of the line of the outer lines is smaller than that of the inner lines.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...