HomeLanguagesturtle.color() method in Python

turtle.color() method in Python

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

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

Syntax:

turtle.color(*args)

Parameters:

Format  Arguments  Description
 turtle.color( colorstring )  colorstring  A string of color name like “red”, “green”, etc.
 turtle.color( (r, g, b) )   (r, g, b)  A tuple of three values r, g, and b using rgb color code
 turtle.color( r, g, b )  r, g, b  Three values r, g, and b using rgb color code

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

Example 1 :

Python3




# importing package
import turtle
 
 
# use forward by 50 (default = black)
turtle.forward(50)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 50 (color = red)
turtle.forward(50)


 
 

Output :

 

 

Example 2:

 

Python3




# importing package
import turtle
 
 
# use forward by 100 (default = black)
turtle.forward(100)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 100 in 90 degrees
# right (color = red)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color((41,41,253))
 
# use forward by 100 in 90 degrees
# right (color = blue)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color(41,253,41)
 
# use forward by 100 in 90 degrees
# right (color = green)
turtle.right(90)
turtle.forward(100)


 
 

Output :

 

 

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32738 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7124 POSTS0 COMMENTS
Nicole Veronica
12254 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12337 POSTS0 COMMENTS
Shaida Kate Naidoo
7235 POSTS0 COMMENTS
Ted Musemwa
7497 POSTS0 COMMENTS
Thapelo Manthata
7215 POSTS0 COMMENTS
Umr Jansen
7185 POSTS0 COMMENTS