Make sure the value is a valid color for tk tcl

I have a class with a variable that should contain a color that will later be used as the color in tcl , and since its value is not displayed to the user as a string, it can contain words or a hexadecimal RGB number (for example, # FF00FF or magenta) .

When I create an object, I want to check that the color is valid. Is there a way to verify that a specific value is a valid color for tcl and tk?

+4
source share
1 answer

You can run the winfo rgb . command winfo rgb . which will try to convert the string to an RGB value. If the string is invalid, the command will throw an error that you can catch.

+4
source

All Articles