You need to learn the difference between a window and a widget. Mainwindows do not have a background, you have to fill them with widgets that have the background capability, and according to your needs, the ability to place widgets on top. The only widget which easily does this is the canvas. As a matter of fact, I worked out a canvas based widget, with a background image at Tk::CanvasDirTree.

A simple example is below. But there are glitches. You may not be able to acheive background transparency on your inserted widgets. A workaround would be to build your own custom canvas widgets out of geometric shapes, and use mouse bindings on them, to simulate the widget actions.

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JPEG; use Tk::PNG; my $file = shift || die "need a bmp, gif,jpg or png as arg 1\n"; my $mw=tkinit; my $canvas = $mw->Scrolled('Canvas')->pack(-expand=>1, -fill=>'both'); my $img = $mw->Photo( -file => $file ); $canvas->createImage(0,0, -image => $img, -anchor => 'nw', -tags => ['img'], ); bunchOfBoxes(); sometext(); MainLoop; sub bunchOfBoxes{ for(0..5){ my $window = $canvas->Checkbutton(-text=> $_); $canvas->createWindow(10, 10+ $_ * 20, -window=> $window); } } sub sometext{ $canvas->createText( 50 , 50, -text => 'foobar', -anchor => 'center', -fill => 'hotpink', ); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: perl/TK - background image by zentara
in thread perl/TK - background image by holandes777

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.