Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter color name to color object

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?

like image 322
ealfonso Avatar asked May 19 '14 18:05

ealfonso


People also ask

How do you use custom colors in Tkinter?

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.

How do you color a label in Python?

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.

What is FG in Tkinter?

Tkinter Button fg option sets the foreground color of button. In other words, the color of the Button's text.


1 Answers

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.

like image 154
DanGar Avatar answered Oct 17 '22 21:10

DanGar