How to set the pen color in Python?
In Python, you can use the turtle module to draw graphics and set the color of the pen. Here are several methods to set the pen color.
- The color red
- verdant
- Azure
- the color yellow
- The color orange
- violet
- A shade of light red
- “the color brown”
- “dark-colored”
- Color that is the absence of darkness.
- “grey”
- The color cyan
- a shade of pink
import turtle
turtle.pencolor("red")
- RGB color values can be used to set the color of a paintbrush using the red, green, and blue color channels. The range of values for color is 0-255. For example:
import turtle
turtle.pencolor(255, 0, 0) # 设置为红色
- You can use hexadecimal color codes to set the color of the brush. The value range for each color channel is 00-FF. For example:
import turtle
turtle.pencolor("#FF0000") # 设置为红色
- By using RGB floating points, you can represent the values of the red, green, and blue color channels using decimal numbers, ranging from 0.0 to 1.0. For example:
import turtle
turtle.pencolor(1.0, 0.0, 0.0) # 设置为红色
No matter which method is used, it is necessary to call turtle.pencolor() before drawing to set the color of the pen.