[pygtk] [GTK3] get background color

Yann Leboulanger asterix at lagaule.org
Thu Aug 1 04:07:02 WST 2013


On 07/31/2013 09:03 PM, Yann Leboulanger wrote:
> On 07/31/2013 07:33 PM, Timo wrote:
>> Op 31-07-13 13:48, Yann Leboulanger schreef:
>>> On 01/29/2013 02:18 PM, Yann Leboulanger wrote:
>>>> Hi,
>>>>
>>>> I'm trying to get the default / current background color of a textview.
>>>> The code I do it:
>>>>
>>>> context = tv.get_style_context()
>>>> color = context.get_background_color(Gtk.StateFlags.NORMAL)
>>>>
>>>> But that returns a fully transparent color (0,0,0,0)
>>>>
>>>> If I first set a custom color with tv.override_background_color(), then
>>>> get_background_color() correctly works and returns the color I set.
>>>>
>>>> So how can I get the current default color?
>>>>
>>>
>>> I still can't get it working with GTK-3.8.2 and python3-gi 3.8.3
>>>
>>> Any idea?
>>
>> Did you wait untill the treeview is realized?
>>
>> treeview.connect('realize', get_bg_color)
>>
>> def get_bg_color(widget):
>>      style = widget.get_style_context()
>>      bgcolor = style.get_background_color(Gtk.StateType.NORMAL)
>>      print(bgcolor)
>
> Yes treeview is realized for sure, this code happens in a callback when
> I press a key.
>

Here is a very simple scrpit that shows the problem. For me it prints:
<Gdk.Color(red=0.000000, green=0.000000, blue=0.000000, alpha=0.000000)>

-- 
Yann
-------------- section suivante --------------
Une pi?ce jointe autre que texte a ?t? nettoy?e...
Nom: test_tv3.py
Type: text/x-python
Taille: 430 octets
Desc: non disponible
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20130731/65483d21/attachment.py>


More information about the pygtk mailing list