Sunday, March 25, 2012

Changing background color of an editable gtk widget

Okay it seems to work fine with labels, entry, objects, but gtkTextView objects appear by default to retain default 'white' background.  Tried several methods for changing background using event box, but it appears color or pixmap images are rendered occluded (blocked) by gtkTextView objects background...hmm...still looking for solution on this.

Easy method for changing background with pixmap image with pygtk 2+...should work in gtk3+ as well

winstyle = window.get_style().copy()
pixbuf = gtk.gdk.pixbuf_new_from_file(filepath)
pixmap, mask = pixbuf.render_pixmap_and_mask()
       
winstyle.bg_pixmap[gtk.STATE_NORMAL] = pixmap 
window.set_style(winstyle)

If you are working with glade you can find the widow style by referencing your ui top level window...

for example,

a window called mydialog, would have its style referenced as above using

winstyle = self.ui.mydialog.get_style().copy()

just need to substitute 'self.ui.mydialog' for 'window' above

and 'filepath' refers to path to pixmap file (I typically use .png files).




No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...