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__
|