[pygtk] Change background color?

Seltzer squabbit7 at gmail.com
Thu Jun 28 11:11:28 WST 2007


that works for most windows, as does modify_bg(...),
but ...

"""
modify_bg() only affects widgets that have an associated
gtk.gdk.Window<http://www.pygtk.org/docs/pygtk/class-gdkwindow.html>.
Widgets that do not have an associated window include
....<http://www.pygtk.org/docs/pygtk/class-gtkarrow.html>gtk.Arrow,
gtk.Bin<http://www.pygtk.org/docs/pygtk/class-gtkbin.html>,
gtk.Box <http://www.pygtk.org/docs/pygtk/class-gtkbox.html>,
gtk.Button<http://www.pygtk.org/docs/pygtk/class-gtkbutton.html>,
gtk.CheckButton <http://www.pygtk.org/docs/pygtk/class-gtkcheckbutton.html>,
gtk.Fixed <http://www.pygtk.org/docs/pygtk/class-gtkfixed.html>,
gtk.Image<http://www.pygtk.org/docs/pygtk/class-gtkimage.html>,
gtk.Label <http://www.pygtk.org/docs/pygtk/class-gtklabel.html>,
gtk.MenuItem <http://www.pygtk.org/docs/pygtk/class-gtkmenuitem.html>,
gtk.Notebook <http://www.pygtk.org/docs/pygtk/class-gtknotebook.html>,
gtk.Paned <http://www.pygtk.org/docs/pygtk/class-gtkpaned.html>,
gtk.RadioButton <http://www.pygtk.org/docs/pygtk/class-gtkradiobutton.html>,
gtk.Range <http://www.pygtk.org/docs/pygtk/class-gtkrange.html>,
gtk.ScrolledWindow<http://www.pygtk.org/docs/pygtk/class-gtkscrolledwindow.=
html>,
gtk.Separator <http://www.pygtk.org/docs/pygtk/class-gtkseparator.html>,
gtk.Table <http://www.pygtk.org/docs/pygtk/class-gtktable.html>,
gtk.Toolbar<http://www.pygtk.org/docs/pygtk/class-gtktoolbar.html>,
gtk.AspectFrame <http://www.pygtk.org/docs/pygtk/class-gtkaspectframe.html>,
gtk.Frame <http://www.pygtk.org/docs/pygtk/class-gtkframe.html>,
gtk.VBox<http://www.pygtk.org/docs/pygtk/class-gtkvbox.html>,
gtk.HBox <http://www.pygtk.org/docs/pygtk/class-gtkhbox.html>,
gtk.VSeparator <http://www.pygtk.org/docs/pygtk/class-gtkvseparator.html>,
gtk.HSeparator <http://www.pygtk.org/docs/pygtk/class-gtkhseparator.html>.
These widgets can be added to a
gtk.EventBox<http://www.pygtk.org/docs/pygtk/class-gtkeventbox.html>to
overcome this
limitation.
"""
(from pygtk reference manual)


so use an event box like it says...   :)
and try something like this:

import gtk
window =3D gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", gtk.mainquit)
label =3D gtk.Label("one, two, testing...")
eb =3D gtk.EventBox()
eb.add(label)
eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue"))
window.add(eb)
window.show_all()
gtk.main()

(NOTE: this code was lifted from
http://eccentric.cx/misc/pygtk/pygtkfaq.html )

also check out the gtk.Widget section of the reference manual
and the gtk.gdk.color_parse one as well.

http://www.pygtk.org/docs/pygtk/

i think that you can also use gtk.gdk.Color(...)
if you need custom colors...

hope this helps

felix

On 6/27/07, Sylvain Saleur <syeric1 at gmail.com> wrote:
>
> Hello!
>
> Thank you very much, I didn't know this FAQ...
>
> So I tried this: http://faq.pygtk.org/index.py?req=3Dshow&file=3Dfaq04.00=
6.htp
>
> But it doesn't work! I'm probably use the wrong way...
>
> If I apply this method to my notebook, it works. But I just want to
> set this background to one page childs. And I can't manage to do
> that...
>
> The structure is : Notebook page =3D> Frame =3D> HBox =3D> ScrolledWindow=
 =3D>
> VBox =3D> Label, image and Button.
>
> I'm sorry if my question has been answered many times but I'm a
> beginner with pygtk and also not a good english speaker...
>
> Cheers
>
> Sylvain
>
> 2007/6/27, John Dennis <jdennis at redhat.com>:
> > On Tue, 2007-06-26 at 22:55 -0400, Sylvain Saleur wrote:
> > > Hello!
> > >
> > > I'm trying to change the background color of a part of my program.
> > > I would like the background in white but I don't know how to do it...
> > >
> > > If you have any suggestion...
> >
> > The FAQ is your friend :-) It tells you the answer to this question and
> > many others.
> >
> > By the way it's listed at the bottom of every message on this list.
> >
> > > Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
> >
> > --
> > John Dennis <jdennis at redhat.com>
> >
> >
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070627/e2860d9e/at=
tachment.htm


More information about the pygtk mailing list