尝试使用WebColors模块将RGB值转换为其名称时会遇到错误
我一直在与WebColors模块挣扎,当我使用RGB_TO_NAME()函数时,它会引发此/这些错误(s)(请记住,请记住IM还使用TKINTER COLORCHOOSER):
file“ c:\ users \ users \ 15CharacTername \ pycharmprojectsssssme \ python \ main4.py”,第16行,in color_choose color = webcolors.rgb_to_name(rg_blist)
文件“ c:\ users \ 15 charactername \ pycharmprojects \ python \ python \ venv \ venv \ lib \ lib \ lib \ lib \ webcolors \ webcolors.py” ),), spec = spec)
文件“ c:\ user \ 15CharacTername \ pycharmprojects \ python \ python \ venv \ lib \ lib \ site-packages \ webcolors.py”,第430行,在hex_to_to_name中 rish value error(“'{}'在{}中没有定义的颜色名称”。格式(hex_value,spec)) ValueError:'#56EB62'在CSS3中没有定义的颜色名称,
这是正常代码:
color = colorchooser.askcolor()
rg_blist = list(color[0])
color = webcolors.rgb_to_name(rg_blist)
这是修改的代码,用于检查它是否是十六进制值(不是):
color = colorchooser.askcolor()
rg_blist = list(color[0])
try:
color = webcolors.rgb_to_name(rg_blist)
except Exception:
print(rg_blist)
输出:
[109,210,40
]打印颜色变量并reran it-这是我得到的:
((105,150,216),'#6996d8') 为什么这是?我想知道 - 我认为它的行为就像.hex_to_name方法/函数。如果应该使用替代方法/功能,请通知我!
我是WebColors模块的新手,因此,如果答案很简单,我就不会惊讶我!提前致谢!
I have been struggling with the webcolors module, and when I use the rgb_to_name() function, It raises this/these error(s)(keep in mind im also using the tkinter colorchooser):
File "C:\Users\15CharacterName\PycharmProjects\python\main4.py", line 16, in color_choose
color = webcolors.rgb_to_name(rg_blist)
File "C:\Users\15CharacterName\PycharmProjects\python\venv\lib\site-packages\webcolors.py", line 470, in rgb_to_name return hex_to_name(rgb_to_hex(normalize_integer_triplet(rgb_triplet)), spec=spec)
File "C:\Users\15CharacterName\PycharmProjects\python\venv\lib\site-packages\webcolors.py", line 430, in hex_to_name
raise ValueError("'{}' has no defined color name in {}".format(hex_value, spec))
ValueError: '#56eb62' has no defined color name in css3
Here is the normal code:
color = colorchooser.askcolor()
rg_blist = list(color[0])
color = webcolors.rgb_to_name(rg_blist)
This is the modified code to check if it was a hexadecimal value(it wasn't):
color = colorchooser.askcolor()
rg_blist = list(color[0])
try:
color = webcolors.rgb_to_name(rg_blist)
except Exception:
print(rg_blist)
output:
[109, 210, 40]
made it print the color variable and reran it- this is what I got:
((105, 150, 216), '#6996d8')
Why is this? I would like to know- I thought it would behave like the .hex_to_name method/function. If an alternate method/function should be used, please notify me!
I'm pretty new to the webcolors module, so it wouldn't suprise me if the answer is simple! Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论