Thursday, October 2, 2025
HomeLanguagesPython – turtle.pencolor() method

Python – turtle.pencolor() method

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.pencolor() :

This method is used to change the color of the ink of the turtle drawing. The default color is black.

Syntax: turtle.pencolor(*args)
 

Arguments: This method have following arguments:

  • colorstring: (optional) colorstring A string of color name like “red”, “green”, etc.
  • (r, g, b): (optional) A tuple of three values r, g, and b using rgb color code.
  • r, g, b: (optional) Three values r, g, and b using rgb color code.

Return: None

Below is the implementation of above method with an example :

Python3




# importing turtle package
import turtle
 
# set turtle shape
turtle.shape("turtle")
 
# set the colormode
turtle.colormode(255)
 
# use forward by 100 pixel
# default pen color is  black
turtle.forward(100)
 
# change the pencolor
# pencolor is red
turtle.pencolor("red")
 
# use forward by 100 pixel
# then 90 degrees right
turtle.right(90)
turtle.forward(100)
 
# change the pencolor
# pencolor is blue
turtle.pencolor((41,41,253))
 
# use forward by 100 pixel
# then 90 degrees right
turtle.right(90)
turtle.forward(100)
 
# change the pencolor
# pencolor is green
turtle.pencolor(41,253,41)
 
# use forward by 100 pixel
# then 90 degrees right
turtle.right(90)
turtle.forward(100)
 
# This code is contributed
# by Deepanshu Rustagi.


 

 

Output :

 

Output turtle pencolor changes demo

 

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11927 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS