To update this, for anyone searching, you don't need a wrapper for a Perl script (although it would be useful for a c program).

Anyways, you can use a BEGIN block, or set the ENV and require Gtk2 instead of use to load it.

What this script does, is load an empty gtkrc file (in the cwd), and it overrides the theme in the /home/user/.gtkrc-2.0 file. Thus making button color changes possible.

#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; # must be before Gtk2 init #BEGIN { $ENV{GTK2_RC_FILES} = 'gtkrc_myapp' } #use Gtk2 '-init'; # or set and require module below $ENV{GTK2_RC_FILES} = 'gtkrc_myapp'; #require Foo; #Foo->import; # if necessary require Gtk2; Gtk2->init; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Z'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(300,200); my $greyh = Gtk2::Gdk::Color->new (0xCCCC,0xCCCC,0xCCCC); my $greyl = Gtk2::Gdk::Color->new (0x9999,0x9999,0x9999); my $redh = Gtk2::Gdk::Color->new (0xFFFF,0,0); my $redl = Gtk2::Gdk::Color->new (0xAAAA,0,0); my $greenh = Gtk2::Gdk::Color->new (0,0xFFFF,0xEEEE); my $greenl = Gtk2::Gdk::Color->new (0,0xFFFF,0xCCCC); my $greend = Gtk2::Gdk::Color->new (0,0xFFFF,0); my $blueh = Gtk2::Gdk::Color->new (0,0xFFFF,0xFFFF); my $bluel = Gtk2::Gdk::Color->new (0,0xCCCC,0xFFFF); $window->modify_bg ('normal', $greenl); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); my $frame0 = Gtk2::Frame->new('Controls'); $vbox->pack_end( $frame0, FALSE, FALSE, 0 ); $frame0->set_border_width(3); $frame0->modify_bg ('normal', $redl); #used for coloring frame my $coleventb0 = Gtk2::EventBox->new(); $frame0->add($coleventb0); my $hbox0 = Gtk2::HBox->new( FALSE, 6 ); $coleventb0->add($hbox0); $hbox0->set_border_width(3); $coleventb0-> modify_bg('normal', $greyl); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox0->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); my $button1 = Gtk2::Button->new('Color-test'); $hbox0->pack_end( $button1, FALSE, FALSE, 0 ); $button1->signal_connect( clicked => sub{ print chr(07),"\n"; # \n or use $|++ }); $button1->modify_bg ('normal', $bluel); $button1->modify_bg ('prelight', $blueh); $button1->modify_bg ('active', $greend); $coleventb0-> modify_bg('normal', $greyl); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re^2: Gtk2: changing Button Color by zentara
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.