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

Last Updated : 24 Dec, 2021

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.pen()

This function is used to return or set the pen's attributes in a 'pen-dictionary' with the following key/value pairs:

This dictionary can be used as an argument for a subsequent pen()-call to restore the former pen-state. Moreover, one or more of these attributes can be provided as keyword-arguments. This can be used to set several pen attributes in one statement.

Syntax : turtle.pen(pen=None, **pendict)

Parameters:

Below is the implementation of the above method with some examples :

Example 1 :

Python3 `

import package

import turtle

check default values

print(turtle.pen())

`

Output :

{'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3,
'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0}

Example 2 :

Python3 `

import package

import turtle

check default to compare

print(turtle.pen())

update with some inputs

turtle.pen(pencolor="red", outline=2)

again check

print(turtle.pen())

`

Output :

{'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3,
'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0}
{'shown': True, 'pendown': True, 'pencolor': 'red', 'fillcolor': 'black', 'pensize': 1, 'speed': 3,
'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 2, 'tilt': 0.0}