Python Colorchooser

末鹿安然 提交于 2021-02-08 07:54:50

问题


So I have some code

from tkinter.colorchooser import askcolor
def colorcode():
    color = askcolor()
    color = color[:2]
    return color
print(colorcode())

Say I click blue.
The response is:
((0.0, 0.0, 255.99609375), '#0000ff')
How can I get only the hexidecimal?
EG:

>>>print(colorcode())
-----
|   | The window <-
-----
('#0000ff')

OR even better, just plain #0000ff Thanks!


回答1:


The hex value is in the second position (1 since python's iterables are zero-indexed), so this simple code should do :

from tkinter.colorchooser import askcolor
def colorcode():
    return askcolor()[1]


来源:https://stackoverflow.com/questions/45927453/python-colorchooser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!