[PYTHON] Possible values for Tkinter color specification

There are quite a few scenes where you specify colors with Tkinter.

frame = Tkinter.Frame(bg='red')

In this example, bg specifies the background color of the frame as a string literal red. However, I was curious about what the available values were, so I looked it up.

Environment used for confirmation

I feel that it is not environment-dependent, so it is just for reference.

Numerical designation

Can be specified as a 4-bit / 8-bit / 12-bit numeric character string.

Tkinter.Frame(bg='#fff') # white
Tkinter.Frame(bg='#000000') # black
Tkinter.Frame(bg='#000fff000') # green

Designation by name

Can be specified with a name such as red or yellow. For what values are available here There was a document on the Tcl / Tk site that is the source (?) Of the Tkinter wrapper.

http://www.tcl.tk/man/tcl8.4/TkCmd/colors.htm

All of the 752 types of color specification strings written here were usable.

There seems to be no problem with the difference between uppercase and lowercase letters.

class TkinterColorsTestCase(unittest.TestCase):

    def test_(self):

        def _assert_color(color):
            try:
                for _color in [
                        #Original value
                        color, 
                        #uppercase letter
                        color.upper(), 
                        #Lowercase
                        color.lower(),
                        ]:
                    Frame(bg=_color)
            except TclError as e:
                self.assertTrue(False, msg=color)

        map(_assert_color, Colors)

if __name__ == '__main__':
    unittest.main()

Is it standardized by the name of the color? I haven't found it for a moment.

Recommended Posts

Possible values for Tkinter color specification
Python Tkinter notes (for myself)
Blender 2.9, Python, hexadecimal color specification