I need to modify a widget's color in some way, for example, to make it darker, greener, to invert it.
The widget's color is given by name, for example, 'orchid4'
.
How do I get RGB values from a color name string?
Asked
Active
Viewed 1,634 times
6

ealfonso
- 6,622
- 5
- 39
- 67
-
1First section: http://effbot.org/tkinterbook/tkinter-widget-styling.htm – atlasologist May 19 '14 at 18:26
-
I did try inspecting into the object, looking at widget's config() info, but the colors stored there are still color names if the color was specified in this way. I even tried looking into the color-object class and source code, but that led me to an unreadable .so file. – ealfonso May 19 '14 at 18:41
1 Answers
4
You should try something like:
In [31]: rgb = button.winfo_rgb("orchid4")
In [32]: rgb
Out[32]: (35723, 18247, 35209)
where button
is the name of your widget object.

DanGar
- 3,018
- 17
- 17
-
What's the range of these numbers? I usually expect colors to be in [0,255]. – Kevin May 19 '14 at 18:32
-
These are 16-bit RGB values which range from 0 to 65535. You can divide each value by 256 if you want the 0 to 255 range. – DanGar May 19 '14 at 18:38