4

I have a class with a variable that supposed to hold a color that will later be used as a color in tcl, and since its value isn't shown to the user as a string, it can hold either words, or an Hex 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 check that a certain value is an valid color for tcl and tk?

SIMEL
  • 8,745
  • 28
  • 84
  • 130

1 Answers1

4

You can run the 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 which you can catch.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685