Tkinter中的命名颜色 [英] Named colors in tkinter
问题描述
如何在tkinter中获取所有已命名颜色的列表?我需要随机选择颜色并将其名称打印给用户.
How can I get a list of all named colors in tkinter? I need to choose colors randomly and print their names to the user.
我在这里找到了所有颜色的列表: Tkinter的颜色图表和Tix使用Python 我宁愿从库中获取列表,也不愿在程序中对其进行硬编码.
I found a list of all colors here: Colour chart for Tkinter and Tix Using Python I would rather get the list from the library than to hardcode it in my program.
推荐答案
对于linux(debian),文件/etc/X11/rgb.txt 具有类似
In case of linux (debian) there is a file /etc/X11/rgb.txt that has lines like
255 250 250 snow
,并且应该易于解析.您的程序可以将颜色定义从该文件(或其副本)读取到列表中,然后从该列表中选择随机颜色.
and should be easy to parse. Your program could read color definitions from that file (or a copy of it) to a list, and then select a random color from that list.
这篇关于Tkinter中的命名颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!