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?
You can use a string specifying the proportion of red, green and blue in hexadecimal digits. For example, "#fff" is white, "#000000" is black, "#000fff000" is pure green, and "#00ffff" is pure cyan (green plus blue). You can also use any locally defined standard color name.
We can apply color on the Label widget and Label Text. To color the widget label, the background or bg keyword is used, and to change the text color of the label widget, the foreground or fg keyword is used. In this example, we have a colored label widget and label text.
Tkinter Button fg option sets the foreground color of button. In other words, the color of the Button's text.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With