Python 蟒蛇龟笔颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20320921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Turtle pen colour
提问by Brennan Wilkes
When I call t.pencolor('83, 58, 27')(turtle is imported as t) I get the TurtleGraphicsError: bad color string: 83, 58, 27even though I have (I think) changed my colour mode.
当我打电话t.pencolor('83, 58, 27')(海龟被导入为 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
采纳答案by Burhan Khalid
You are passing in a stringwith 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). 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.
允许四种输入格式:
pencolor() 将当前画笔颜色作为颜色规范字符串或元组返回(参见示例)。可用作另一个 color/pencolor/fillcolor 调用的输入。
pencolor(colorstring) 将 pencolor 设置为 colorstring,即 Tk 颜色规范字符串,例如“red”、“yellow”或“#33cc8c”。
pencolor((r, g, b)) 将 pencolor 设置为由 r、g 和 b 的元组表示的 RGB 颜色。r、g 和 b 中的每一个都必须在 0..colormode 范围内,其中 colormode 是 1.0 或 255(请参阅 colormode())。
pencolor(r, g, b) 将 pencolor 设置为由 r、g 和 b 表示的 RGB 颜色。r、g 和 b 中的每一个都必须在 0..colormode 范围内。
So you can also send in a tupleof your colors, but again they need to be integers not strings:
所以你也可以发送一个你的颜色元组,但它们再次需要是整数而不是字符串:
t.pencolor((83, 58, 27))

