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

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing turtle package
import turtle
  
# set turtle shape
turtle.shape("turtle")
  
# set the colormode
turtle.colormode(255)
  
# use forward by 100 pixel
# deault 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.

chevron_right


Output :

Output turtle pencolor changes demo

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.