简体   繁体   English

蟒蛇龟笔颜色

[英]Python Turtle pen colour

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.pencolor('83, 58, 27') (turtle 被导入为 t)时,我得到TurtleGraphicsError: bad color string: 83, 58, 27即使我(我认为)改变了我的颜色模式。

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

I run python 2.7 on OS 10.9我在 OS 10.9 上运行 python 2.7

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)

There are multiple ways to use pencolor , from the documentation :文档中有多种使用pencolor方法:

Four input formats are allowed:允许四种输入格式:

pencolor() Return the current pencolor as color specification string or as a tuple (see example). pencolor() 将当前画笔颜色作为颜色规范字符串或元组返回(参见示例)。 May be used as input to another color/pencolor/fillcolor call.可用作另一个 color/pencolor/fillcolor 调用的输入。

pencolor(colorstring) Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c". pencolor(colorstring) 将 pencolor 设置为 colorstring,即 Tk 颜色规范字符串,例如“red”、“yellow”或“#33cc8c”。

pencolor((r, g, b)) Set pencolor to the RGB color represented by the tuple of r, g, and b. pencolor((r, g, b)) 将 pencolor 设置为由 r、g 和 b 的元组表示的 RGB 颜色。 Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()). r、g 和 b 中的每一个都必须在 0..colormode 范围内,其中 colormode 是 1.0 或 255(请参阅 colormode())。

pencolor(r, g, b) Set pencolor to the RGB color represented by r, g, and b. pencolor(r, g, b) 将 pencolor 设置为由 r、g 和 b 表示的 RGB 颜色。 Each of r, g, and b must be in the range 0..colormode. r、g 和 b 中的每一个都必须在 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))

For me, I think you can delete the apostrophes as it is not a string, but a value.对我来说,我认为你可以删除撇号,因为它不是一个字符串,而是一个值。 Like this: t.pencolor(83, 58, 27) .像这样: t.pencolor(83, 58, 27)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM