in reply to Perl::Gtk and Color tutorial

I think this should get you started.

Disclaimer: I havent used Perl::Gtk (yet)...

---Lars

Notice the mentioning about colour fiddling should be left for the theme to decide...

Update: Realized this was Gtk2 - this link should be the 'plain' Gtk way.

Replies are listed 'Best First'.
Re^2: Perl::Gtk and Color tutorial
by Crackers2 (Parson) on Dec 13, 2004 at 20:47 UTC

    I already looked at that Gtk link (in fact I mentioned it in my question), but it doesn't really help me. I tried to adapt the example to work with a label, but $label->window returns undef so it dies.

    my $l = new Gtk::Label( "Success" ); my $colormap = $l->window->get_colormap(); my $gdk_color = Gtk::Gdk::Color->parse_color( "green" ); $gdk_color = $colormap->color_alloc( $gdk_color ); $l->window->set_background( $gdk_color );

    Looking at it a bit closer, it seems to expect that the widget is already added to a realized window. That's unfortunate, since I'd like for my module to return a Gtk::Table that can then be added to a window at will.

    As for the theme remark: I would compare what I'm working on to a web browser in that regard. There's some general UI that should be affected by themes (cfr. the browser chrome), and then some content that should be shown a certain way no matter what the theme (cfr. a webpage in the browser)

      take a look at the perl-gtk2 class docs. Label is a subclass of widget, which provides the get_colormap function. In your above code change:
      my $colormap = $l->window->get_colormap();
      to:
      my $colormap = $l->get_colormap();
      I have not used this but it looks right from the docs.

        That does get me a little further, but now it still fails on the last line:

        my $l = new Gtk::Label( "Success" ); my $colormap = $l->get_colormap(); my $gdk_color = Gtk::Gdk::Color->parse_color( "green" ); $gdk_color = $colormap->color_alloc( $gdk_color ); $l->window->set_background( $gdk_color );

        $l->window is undefined, so can't do a set_background on it, and $l->set_background doesn't appear to exist either.