Jan 10, 2014

HowTo: Add Tiled Background Image to Perl Gtk2 Window



tiled-background.pl
#!/usr/bin/perl -w

use strict;
use Gtk2 '-init';

my $window = Gtk2::Window->new();
$window->signal_connect('destroy'=>sub{Gtk2->main_quit();});
$window->set_size_request(200,200);
background("tile01.jpg",$window);
$window->show_all();
Gtk2->main();

sub background {
my ($image,$win) = @_;
my $back_pixbuf =  Gtk2::Gdk::Pixbuf->new_from_file($image);
my ($pixmap,$mask) = $back_pixbuf->render_pixmap_and_mask(255);
my $style = $win->get_style();
$style=$style->copy();
$style->bg_pixmap("normal",$pixmap);
$window->set_style($style);
}


No comments:

Post a Comment