Python Gtk3 set or change color for GdkPixbuf.Pixbuf from Gdk.RGBA or Gdk.Color
<p>How can I set or change the color of a GdkPixbuf.Pixbuf ?</p>

<p>I can create and fill:</p>

<pre><code>pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 32, 16)
pixbuf.fill(0x000000)
</code></pre>

<p>But how to get a color from from Gdk.RGBA or Gdk.Color?</p>

<p>edit:</p>

<p>I tried so much things now but nothing is working, for example:</p>

<pre><code>import webcolors
from gi.repository import Gdk
color = Gdk.color_parse("orange")
hexe = webcolors.rgb_to_hex(color.to_floats()) 
</code></pre>

<p>But I still have the problem that I need 0x at the beginning and it have to be a number.</p>

<p>Wow, this was very hard. I finally found an solution:</p>

<pre><code>pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 16, 16)
color =  Gdk.color_parse("orange")
fillr = (color.red / 256) &lt;&lt; 24
fillg = (color.green / 256) &lt;&lt; 16
fillb = (color.blue / 256) &lt;&lt; 8
fillcolor = fillr | fillg | fillb | 255
pixbuf.fill(fillcolor)
</code></pre>

<p>Thanks to starcal (<a href="https://github.com/ilius/starcal/blob/master/scal3/ui_gtk/desktop.py" rel="nofollow">https://github.com/ilius/starcal/blob/master/scal3/ui_gtk/desktop.py</a>) for the code and and to <a href="http://nullege.com/" rel="nofollow">http://nullege.com/</a> helped me to find this.</p>

python colors gtk3