I am trying to set the background color for a pyGtk window which has a single DrawingArea widget. With this code I always get a random color everytime I launch the script:
widget = gtk.DrawingArea()
widget.show()
window = gtk.Window()
window.add(widget)
col = gtk.gdk.Color('#010')
window.present()
widget.window.set_background(col)
window.connect('delete-event', gtk.main_quit)
gtk.main()
I also tried using widget.modify_bg(gtk.STATE_NORMAL, col)
instead of the set_background
line, and I always get a black background.
What am I missing?
Ok, it seems like I was struggling too much with other things, and I didn't realize that I set the test color to #010, which is, obviously, almost black.
Using modify_bg
works, just remember to set a reasonable color ;)
This is the working code:
widget = gtk.DrawingArea()
widget.show()
window = gtk.Window()
window.add(widget)
col = gtk.gdk.Color('#0f0')
window.present()
widget.modify_bg(gtk.STATE_NORMAL, col)
window.connect('delete-event', gtk.main_quit)
gtk.main()
By the way, does anybody know why widget.window.set_background()
sets a random color?