简体   繁体   中英

Portable method to get a list of accepted color names with tkinter

It seems that Python Tkinter and Tcl/Tk ask the system for color names and do not maintain it themselves. Looking at the standard Python/Tcl/Tk sources does not show any of those colors. You can only find them in color.n which is part of the Tk documentation and in an optional pygment library.

Is there a portable way to ask the system itself (and not any other source which might or might not match the system one) through Python and Tkinter or any other GUI library, for a list of the available color names?

This was previously marked as a duplicate of Named colors in tkinter , but the only answer there involves reading /etc and so is Linux-specific. I am looking for a portable method that would work with Linux, Windows, and Mac.

you can validate the color : widget.winfo_rgb('color')

If color string is wrong the error arises

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM