📜  Python – turtle.pencolor() 方法

📅  最后修改于: 2022-05-13 01:55:08.557000             🧑  作者: Mango

Python – turtle.pencolor() 方法

turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。

乌龟.pencolor():

此方法用于更改海龟绘图的墨水颜色。默认颜色为黑色。

以下是上述方法的实现示例:

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.


输出 :

输出海龟笔颜色变化演示