Saturday, November 15, 2025
HomeLanguagesturtle.colormode() function in Python

turtle.colormode() function 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.colormode()

This function is used to return the color mode or set it to 1.0 or 255. (r, g, b) values of color triples have to be in range 0 to c mode. It requires only one argument as “cmode”  one of the values 1.0 or 255.

Syntax :

turtle.colormode(mode=None)

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

Example 1 :

Python3




# import package
import turtle
  
# check the default value
print(turtle.color())


Output :

('black', 'black')

Example 2 :

Python3




# import package
import turtle
  
# set the colormode to 255
turtle.colormode(255)
# set color
turtle.color(0,0,255)
  
# motion
for i in range(20):
    turtle.forward(2+2*i)
    turtle.right(90)
  
# set the colormode to 1.0
turtle.colormode(1.0)
  
# set color
turtle.color(1.0,0,0)
  
# motion
for i in range(20):
    turtle.forward(40+4*i)
    turtle.right(90)


Output :

RELATED ARTICLES

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6768 POSTS0 COMMENTS
Nicole Veronica
11919 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11990 POSTS0 COMMENTS
Shaida Kate Naidoo
6897 POSTS0 COMMENTS
Ted Musemwa
7149 POSTS0 COMMENTS
Thapelo Manthata
6850 POSTS0 COMMENTS
Umr Jansen
6841 POSTS0 COMMENTS