Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Yeah, I feel your pain with trying to get to the lowlevel stuff in the docs. For what it's worth, I asked a similar question awhile back on the gtk-perl maillist, on whether you could set a style from a base64 encoded xpm contained within the file. The answer was "no". You would need to write it to a temp file, then incorporate it in as a style.

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

In reply to Re: Perl-Gtk2::How to set a window background image. by zentara
in thread Perl-Gtk2::How to set a window background image. by turo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-06-07 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?