in reply to GTK widgets - set colors

It gets complicated with Gtk2, because it uses a basic system style file in ./~gtkrc-2.0 , further complicated by Ubuntu's advanced theme, which probably uses pixmaps, which are hard to override. Google for all the gory gtkrc-2.0 details. It does get complex, and you can spend days trying to figure out the themes.

The gtkrc-2.0 file is hard to override for some widgets. See Setting widget bg color in Gtk2

Here is a general purpose override for the gtkrc style file for the Text box. Notice the color of the cursor needs special handling.

#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; Gtk2::Rc->parse_string(<<__); style "my_text" { font_name ="sans 24" text[NORMAL] = "#FFAA00" base[NORMAL] = "#000000" GtkTextView::cursor-color = "red" } style "my_cursor"{ fg[NORMAL] = "#FF0000" } widget "*Text*" style "my_text" __ 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(400,400); 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); my $ebutton = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $ebutton, FALSE, FALSE, 0 ); $ebutton->signal_connect( clicked => \&delete_event ); # Create a textbuffer to contain that string my $textbuffer = Gtk2::TextBuffer->new(); $textbuffer->set_text('yadda yadda yadda'); # Create a textview using that textbuffer my $textview = Gtk2::TextView->new_with_buffer($textbuffer); # Add the textview to a scrolledwindow my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef ); $scrolledwindow->add($textview); $vbox->pack_start($scrolledwindow, 1, 1, 0 ); $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.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: GTK widgets - set colors
by ronlewis (Initiate) on Mar 29, 2011 at 17:57 UTC

    zentara, Khen1950fx, halfcountplus,

    Thanks for your generous help. The code you offered does the job very nicely, and I've learned a thing or two about GTK from your posts.

    Ron