python - 我在哪里可以找到在 python 中使用的十六进制颜色代码列表?

标签 python python-3.x colors turtle-graphics

我正在使用 turtle 图形模块做一个小练习项目。我创造了 8 只 turtle ,想随机改变它们的颜色。我正在考虑使用随机模块随机选择一种颜色。但为此,我需要一个字符串格式的十六进制颜色代码列表。我在哪里可以找到这样的列表?或者如果有一个图书馆有这样一个列表,那也可以。

import turtle
import random

p1 = turtle.Turtle()
p2 = turtle.Turtle()
p3 = turtle.Turtle()
p4 = turtle.Turtle()
p5 = turtle.Turtle()
p6 = turtle.Turtle()
p7 = turtle.Turtle()
p8 = turtle.Turtle()
players = [p1, p2, p3, p4, p5, p6, p7, p8]

colors = []  # need a list of hex codes of colors

for player in players:
    player.shape('turtle')
    player.color(random.choice(colors))
    player.pu()
    player.goto(-225, 180 - 27*players.index(player))


while True:
    for _ in players:
        _.forward(random.randint(1, 10))


turtle.done()

我已经在这里复制了我的代码的相关部分。我怎样才能找到 turtle 库识别的颜色列表?

最佳答案

您可以使用 matplotlib 中的颜色:

list(matplotlib.colors.cnames.values())

关于python - 我在哪里可以找到在 python 中使用的十六进制颜色代码列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54955774/

相关文章:

python : Multiple file processing is very slow

android - 使用 PyCrypto 验证来自 Google Licensing 的 RSA 签名

python - 将队列与 tkinter(和线程)一起使用

java - bufferedImage.getRGB(x, y) 不产生 alpha

python - 如何检查 float

python - 为什么pymysql(0.9.2)调用存储过程,有时获取输出参数为None?

Python 3.5 |从网站抓取数据

python - 可以在 MySQL 表中存储字节(Fernet token )吗? Python

java - 如何将 javafx.scene.paint.Color 转换为 java.awt.Color ?

python - 如何在 wxpython 中使用命名颜色?