gpt4 book ai didi

Python Turtle 笔色

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:04 25 4
gpt4 key购买 nike

当我调用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com