in reply to Perl-Gtk2::How to set a window background image.
If you think about it, a background pixmap probably needs to be setup before anything can be drawn onto it. The normal method they are setting up, is to use styles, and have your pixmaps stored under a style name in the styles directory. So maybe it will take them a few years to get around to it. :-)
Another problem I've experienced with a Gdk window, is that it is not there until the window is mapped onto the screen. In the code below, if you try to get the gdkwindow in the main program, before show_all() is called, it will be undefined. The following is the closet I could get to what you want to do. It runs without error, but the background does not change, neither for a pixmap, nor a color. There probably is some command needed to redraw the window? I don't know, but if you find a way, please post it.
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $rc_style = Gtk2::RcStyle->new; $rc_style->bg_pixmap_name('normal', 'bunny.xpm'); my $window = Gtk2::Window->new('toplevel'); $window->set_title('Embed test'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(500,500); $window->modify_style ($rc_style); 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); $vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); my $button1 = Gtk2::Button->new('Set BG'); $hbox->pack_end( $button1, FALSE, FALSE, 0 ); $button1->signal_connect( clicked => \&set_bg ); my $vbox1 = Gtk2::VBox->new( 0, 5 ); $vbox->pack_end ($vbox1, TRUE, TRUE, 0); my $btn = Gtk2::Button->new_from_stock('gtk-quit'); $btn->signal_connect( 'clicked' => \&delete_event ); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } ########################################## sub set_bg{ my @z_xpm = ( '20 3 2 1', ' c None', '+ c #1A1A1A', '+ + + + + + + + + + ', '+ + + + + + + + + + ', '+ + + + + + + + + + ',); my $gdkwindow = $vbox->window; print "$gdkwindow\n"; #my $colormap = Gtk2::Gdk::Colormap->get_system; my $colormap = $window->get_default_colormap; my $pixmap = Gtk2::Gdk::Pixmap->colormap_create_from_xpm_d (undef, $colormap, undef, @z_xpm ); # my $black = Gtk2::Gdk::Color->new (0,0,0); # $gdkwindow->set_background($black); $gdkwindow->set_back_pixmap($pixmap); $window->show_all(); }
I'm not really a human, but I play one on earth. flash japh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl-Gtk2::How to set a window background image.
by turo (Friar) on Feb 14, 2006 at 17:38 UTC | |
by zentara (Archbishop) on Feb 14, 2006 at 20:11 UTC |