ronlewis has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to create a simple gtk-perl window in which to display text.
I'm using Ubuntu, on which the default colour scheme is black text on a white background. I want to change those colours.
I've examined the docs and tutorials, and there seem to be two possible approaches. The first is to use tags - this works well, but it only affects the displayed text - not the whole window.
The second approach was demonstrated by zentara (http://www.perlmonks.org/?node_id=634916) . His script successfully changes the colours of button widgets, but when I try to use the same code to change a textview widget, nothing happens.
Here's an example script. Tags work; the displayed text is white on a black background. Some calls to modify_bg() work - the window's scroll bars are green. Other calls to modify_bg() do not work. What I'm trying to achieve is white text on a black background.
#!/usr/bin/perl -w # Short script to demonstrate a GTK ScrollWindow, which has a white ba +ckground # by default; I'd like to use a different colour scheme # # Based on the replies by zentara at # http://www.perlmonks.org/?node_id=636366 # http://www.perlmonks.org/?node_id=633983 BEGIN { $ENV{GTK2_RC_FILES} = 'gtkrc_myapp' } use Gtk2 '-init'; use Gtk2::Helper; use Glib qw(TRUE FALSE); use strict; our $Buffer; our $TextView; # Create the widget &createWindow; # Insert some text into the window on an endless loop for (;;) { &insertText("Hello world!\n"); &insertText("Time to party!\n"); } sub createWindow { # Define colours 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); # Create a window widget my $windowHandle = Gtk2::Window->new('toplevel'); $windowHandle->signal_connect('delete_event' => sub { exit;}); $windowHandle->set_border_width(0); $windowHandle->set_position('center_always'); $windowHandle->modify_bg ('normal', $greenl); # Create an HBox within the window my $hbox = Gtk2::HBox->new(); $hbox->set( "border_width" => 0 ); $hbox->modify_bg ('normal', $bluel); $windowHandle->add($hbox); # Create a scrolling window my $sw = Gtk2::ScrolledWindow->new; $sw->set_size_request(400,300); $sw->modify_bg ('normal', $redl); # Create a text view $TextView = Gtk2::TextView->new(); $TextView->modify_bg ('normal', $greyl); # Create a text buffer $Buffer = $TextView->get_buffer(); # Create a colour tag for the text buffer $Buffer->create_tag('default', foreground => 'white', background => 'black', ); # Pack the widgets $sw->add($TextView); $hbox->pack_start($sw,1, 1, 1 ); # Put the window widget (and all its children) into the event queu +e $windowHandle->show_all; return 1; } sub insertText { my ($text) = @_; $Buffer->insert_with_tags_by_name($Buffer->get_end_iter, $text,'de +fault'); Gtk2->main_iteration while Gtk2->events_pending; $TextView->scroll_to_iter($Buffer->get_end_iter,0,0,0,0); + return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GTK widgets - set colors
by halfcountplus (Hermit) on Mar 26, 2011 at 13:43 UTC | |
by ronlewis (Initiate) on Mar 27, 2011 at 06:41 UTC | |
|
Re: GTK widgets - set colors
by zentara (Cardinal) on Mar 27, 2011 at 14:34 UTC | |
by ronlewis (Initiate) on Mar 29, 2011 at 17:57 UTC | |
|
Re: GTK widgets - set colors
by Khen1950fx (Canon) on Mar 27, 2011 at 04:17 UTC |