问题
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