The problem with the below code ( taken from the links above) is that you cant have the color and the label on the same button. That is what I want to do. Any ideas? Another option would be to 'gray-out' the button.
#!/usr/bin/perl -w use strict; package Mup::ColorButton; use Gtk2; use Glib::Object::Subclass Gtk2::Button::, signals => { color_changed => {}, show => \&on_show, }, properties => [ Glib::ParamSpec->int ( 'red', 'Red', 'The Red component of the RGB color', 0, 0xffff, 0xffff, [qw/readable writable/] ), Glib::ParamSpec->int ( 'green', 'Green', 'The Green component of the RGB color', 0, 0xffff, 0xffff, [qw/readable writable/] ), Glib::ParamSpec->int ( 'blue', 'Blue', 'The Blue component of the RGB color', 0, 0xffff, 0xffff, [qw/readable writable/] ), ] ; sub INIT_INSTANCE { my $self = shift; $self->{red} = 0xffff; $self->{green} = 0xffff; $self->{blue} = 0xffff; my $frame = Gtk2::Frame->new; $frame->set_border_width (3); $frame->set_shadow_type ('etched-in'); $self->add ($frame); $frame->show; my $event_box = Gtk2::EventBox->new; $event_box->set_size_request (14, 14); $frame->add ($event_box); $event_box->show; $self->{colorbox} = $event_box; } sub on_show { my $self = shift; $self->set_color (red => $self->{red}, green => $self->{green}, blue => $self->{blue}); $self->signal_chain_from_overridden; } sub set_color { my $self = shift; my %params = @_; my $color = Gtk2::Gdk::Color->new ($params{red}, $params{green}, $params{blue}); $self->{colorbox}->get_colormap->alloc_color ($color, 0, 1); $self->{colorbox}->modify_bg ('normal', $color); $self->{colorbox}->modify_bg ('active', $color); $self->{colorbox}->modify_bg ('prelight', $color); $self->{red} = $params{red}; $self->{green} = $params{green}; $self->{blue} = $params{blue}; $self->signal_emit ('color-changed'); } package main; use Gtk2 -init; my $window = Gtk2::Window->new; $window->set_title ('Color buttons'); $window->set_border_width (6); $window->signal_connect (delete_event => sub { Gtk2->main_quit; 1 }); my $vbox = Gtk2::VBox->new; $window->add ($vbox); $vbox->show; my $foo = Mup::ColorButton->new (red => 0xaaaa, green => 0x0, blue => +0xffff); $vbox->pack_start ($foo, 1, 1, 0); $foo->show; $foo->signal_connect (clicked => sub { my $self = shift; my $dialog = Gtk2::ColorSelectionDialog->new ('pick a +color'); my $c = Gtk2::Gdk::Color->new ($self->{red}, $self->{green}, $self->{blue}); $self->{colorbox}->get_colormap->alloc_color ($c, 0, 1 +); $dialog->colorsel->set_current_color ($c); if ('ok' eq $dialog->run) { my $c = $dialog->colorsel->get_current_color; $self->set_color (red => $c->red, green => $c->green, blue => $c->blue); } $dialog->destroy; }); $foo->signal_connect (color_changed => sub { warn "the color changed - now " . join (", ", $_[0]->get (qw/red green blue/)) . ". i should do something!"; }); $window->show; Gtk2->main;

In reply to Re^2: Gtk2: changing Button Color by deadpickle
in thread Gtk2: changing Button Color by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.