编程语言
首页 > 编程语言> > Python龟笔颜色

Python龟笔颜色

作者:互联网

当我调用t.pencolor(‘83,58,27’)(乌龟被导入为t)时,我得到了TurtleGraphicsError:错误的颜色字符串:83,58,27即使我(我认为)改变了我的颜色模式.

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

我在OS 10.9上运行python 2.7

解决方法:

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

t.pencolor(83, 58, 27)

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.

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

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

标签:turtle-graphics,python
来源: https://codeday.me/bug/20190825/1718207.html