问题描述
当我调用 t.pencolor('83, 58, 27')
(乌龟被导入为 t)时,我得到 TurtleGraphicsError: bad color string: 83, 58, 27
即使我(我认为)改变了我的颜色模式.
When I call t.pencolor('83, 58, 27')
(turtle is imported as t) I get the TurtleGraphicsError: bad color string: 83, 58, 27
even though I have (I think) changed my colour mode.
t.colormode(255)
t.pencolor('83, 58, 27')
我在 OS 10.9 上运行 python 2.7
I run python 2.7 on OS 10.9
推荐答案
你传入了一个带有三种颜色的字符串,你需要将这三种颜色作为三个单独的整数参数传递,像这样:
You are passing in a string with three colors, where you need to pass the three colors as three separate integer arguments, like this:
t.pencolor(83, 58, 27)
有多种使用 pencolor
的方法,来自 文档:
There are multiple ways to use pencolor
, from the documentation:
允许四种输入格式:
钢笔颜色()将当前画笔颜色作为颜色规范字符串或元组返回(参见示例).可以用作另一个的输入color/pencolor/fillcolor 调用.
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)将 pencolor 设置为 colorstring,即 Tk 颜色规范字符串,例如red"、yellow"或#33cc8c".
pencolor(colorstring) Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c".
pencolor((r, g, b))将 pencolor 设置为由 r、g 和 b 的元组表示的 RGB 颜色.r、g 和 b 中的每一个都必须在 0..colormode 范围内,其中colormode 为 1.0 或 255(请参阅 colormode()).
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)将 pencolor 设置为由 r、g 和 b 表示的 RGB 颜色.r、g 和 b 中的每一个都必须在 0..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.
所以你也可以发送一个元组你的颜色,但同样它们需要是整数而不是字符串:
So you can also send in a tuple of your colors, but again they need to be integers not strings:
t.pencolor((83, 58, 27))
这篇关于蟒蛇龟笔颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!