Crackers2 has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone have a good introduction on how to use colors with Gtk? I'm talking about relatively simple things like setting the background color of a label, or changing the bordercolor of a Gtk::Frame.

The Perl GTK tutorial only has one rather terse example in the Color Selection Dialogs section, and Google doesn't seem to give me much more information either. There's some examples in C for which I can't immediately find a perl equivalent, and some questions from other people without satisfactory answers

Even a supersearch on "gtk" and "color" in the monastery doesn't seem to reveal anything.

Can anyone give me a few examples, or even better, a tutorial link?

Replies are listed 'Best First'.
Re: Perl::Gtk and Color tutorial
by EverLast (Scribe) on Dec 13, 2004 at 19:13 UTC
    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.

      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.