Python Turtle 笔色

标签 python turtle-graphics

当我调用 t.pencolor('83, 58, 27')(turtle 被导入为 t)时,我得到了 TurtleGraphicsError: bad color string: 83, 58, 27 即使我(我认为)改变了我的颜色模式。

t.colormode(255)    
t.pencolor('83, 58, 27')

我在 OS 10.9 上运行 python 2.7

最佳答案

您正在传递一个具有三种颜色的字符串,您需要将这三种颜色作为三个单独的整数参数传递,如下所示:

t.pencolor(83, 58, 27)

有多种使用pencolor的方法,来自documentation :

Four input formats are allowed:

pencolor() Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call.

pencolor(colorstring) Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c".

pencolor((r, g, b)) Set pencolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()).

pencolor(r, g, b) Set pencolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.

所以你也可以发送你的颜色的元组,但同样它们需要是整数而不是字符串:

t.pencolor((83, 58, 27))

关于Python Turtle 笔色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20320921/

相关文章:

python - 在 Python Turtle 中围绕一个点转动简单的多边形

python - 给定时间原点,如何将日期时间从十进制转换为 “%y-%m-%d %H:%M:%S”?

python - 如何使用 matplotlib 将数组中的数字绘制为注释?

python - 在python turtle 绘图中隐藏 turtle

python - 如何让 turtle 图形在绘制时不显示 turtle ?

python - 在 Python 中绘制分形树

python - docker-compose 卷未正确安装

python - BigQuery 自动将时间戳时区转换为 UTC

python - 如何使用Python计算for循环中的表达式?

python - while 循环中的 time.sleep 函数不断导致程序崩溃,解决方案还是替代方法?