I mention this in case you need to worry about portability. Many installations are using pixmap based themes now, so people running your code, will not be seeing what you think. In discussions on the maillists, all the experts say "do not try to override someone's theme". I guess that's the way it's going, even though I personally like to customize colors.
I would say to be sure that your end user is seeing what you want, use the pango markup, as shown in the second example.
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; Gtk2::Rc->parse_string(<<__); style "default" { bg_pixmap[NORMAL] = "<none>" bg_pixmap[INSENSITIVE] = "<none>" bg_pixmap[ACTIVE] = "<none>" bg_pixmap[PRELIGHT] = "<none>" bg[NORMAL] = { 1.0, 1.0, 1.0 } }class "GtkWidget" style "default" __ my $greyl = Gtk2::Gdk::Color->new (0x9999,0x9999,0x9999); my $bluel = Gtk2::Gdk::Color->new (0,0xCCCC,0xFFFF); my $red = Gtk2::Gdk::Color->new (0xFFFF,0,0); my $white = Gtk2::Gdk::Color->new (0xFFFF,0xFFFF,0xFFFF); my $window = Gtk2::Window->new('toplevel'); $window->signal_connect( destroy => sub { Gtk2->main_quit; } ); $window->set_title("Label"); my $vbox = Gtk2::VBox->new( FALSE, 5 ); $window->add($vbox); $window->set_border_width(5); $window->set_size_request(300,200); #$window->modify_bg('normal',$greyl); my $frame = Gtk2::Frame->new("Colored Label"); my $label = Gtk2::Label->new("This is a Colored Label"); $label->modify_fg('normal', $white); $frame->modify_bg('normal', $red); $vbox->pack_start( $frame, FALSE, FALSE, 0 ); #used for coloring background my $coleventb0 = Gtk2::EventBox->new(); $coleventb0->modify_bg ('normal', $bluel); $coleventb0->set_border_width(2); $frame->add($coleventb0); $coleventb0->add($label); $window->show_all; Gtk2->main;
#! /usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_border_width(5); $window->set_position('center_always'); my $vbox = &ret_vbox(); #add and show the vbox $window->add($vbox); $window->show(); Gtk2->main(); sub ret_vbox { #create a vbox to pack the following widgets my $vbox = Gtk2::VBox->new(FALSE,5); #create a label that will demo pango markup my $label_w_markup = Gtk2::Label->new(); $label_w_markup->set_markup("<span background = 'black' foreground= + 'green' size=\"40000\">Label with <i>markup</i></span>"); $vbox->pack_end($label_w_markup,FALSE,FALSE,4); $vbox->pack_end(Gtk2::HSeparator->new(),FALSE,FALSE,4); $vbox->show_all(); return $vbox; }
In reply to Re: Setting widget bg color in Gtk2
by zentara
in thread Setting widget bg color in Gtk2
by neptuneray
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |