Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Window with background image and transparent listbox

by zentara (Archbishop)
on Aug 19, 2010 at 13:33 UTC ( #856025=note: print w/ replies, xml ) Need Help??

in reply to Window with background image and transparent listbox

As Khen1950fx pointed out, Tk::Zinc is the only Tk canvas that does transparency, and it can be tricky. But if you just want to implement a window with a background image, and a listbox type display on top of it, try making your own on a Tk::Canvas or Tk::Zinc canvas. See the demo of CanvasDirTree for an example on a regular Tk canvas.

You could load an image onto a canvas, then embed a listbox into the canvas, like this similar example:

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $width = 500; my $height = 500; $mw->fontCreate('big', -family=>'courier', -weight=>'bold', -size=>int(-18*18/14)); my $canv = $mw->Canvas( -bg => 'lightsteelblue', -relief => 'sunken', -width => $width, -height => $height)->pack(-expand => 1, -fill => 'both'); my $text = $mw->Scrolled('Text', -bg=>'lightyellow', -scrollbars=>'osoe', ); my $textcontainer = $canv->createWindow( $width/2, $height/2, -window => $text, -width => $width -200, -height => $height-200, -state => 'normal'); my $button = $mw->Button( -bg=>'lightblue', -text=>'Push Me', -command=> sub{ $text->insert('end',time."\n")}, ); my $butcontainer = $canv->createWindow( 125, 25, -window => $button, -width => 125, -height => 25, -state => 'normal'); my $ctext = $canv->createText( 300,20, -font=>'big', -fill=> 'white', -text=>'la di da'); bunchOfBoxes(); $text->focus; MainLoop(); sub bunchOfBoxes { for(0..10){ my $window = $canv->Checkbutton(-text=> $_); $canv->createWindow(450, 20 + ($_ * 20), -window=> $window); } } __END__
Zinc can embed widgets too, and you can play with transparency.
#!/usr/bin/perl -w use strict; use Tk; use Tk::Zinc; my $mw = MainWindow->new(); my $zinc = $mw->Zinc(-backcolor => 'gray', -relief => 'sunken', -width => 400, -height => 300)->pack(-expand => 1, -fill => 'both'); my $xtermWidth = 300; my $xtermHeight = 200; ## this Frame is needed for including the xterm in Tk::Zinc my $xtermContainer = $zinc->Frame(-container => 1); my $xtid = $xtermContainer->id(); print "$xtid\n"; # converting the id from HEX to decimal as xterm requires a decimal Id my ($xtId) = sprintf hex $xtid; print "$xtId\n"; my $label = $zinc->add('text', 1, -text => "Hide xterm", -position => [150, 30]); my $dcontitem = $zinc->add('window', 1, -window => $xtermContainer, -position => [50, 75], -width => $xtermWidth+4, -height => $xtermHeight+4, -visible => 1); $zinc->bind($label, '<1>', \&hideShow); sub hideShow { if ($zinc->itemcget($label, -text) =~ /Hide/) { $zinc->itemconfigure($label, -color => 'yellow', -text => "Show xterm"); $zinc->itemconfigure($dcontitem, -visible => 0); } else { $zinc->itemconfigure($label, -color => 'black', -text => "Hide xterm"); $zinc->itemconfigure($dcontitem, -visible => 1); } } my $width = $xtermWidth/10; my $height = $xtermHeight/20; system("xterm -fn 10x20 -geometry ${width}x${height} -into $xtId & +"); MainLoop(); __END__

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Comment on Re: Window with background image and transparent listbox
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://856025]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2015-07-02 13:09 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (38 votes), past polls