Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Window with background image and transparent listbox

by HelAu (Initiate)
on Aug 19, 2010 at 07:57 UTC ( #855974=perlquestion: print w/ replies, xml ) Need Help??
HelAu has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'd like to have a window with a background image, and in the middle of the window a transparent listbox.
Is that possible with perl tk ?

Thanks in advance
Helmut

Comment on Window with background image and transparent listbox
Re: Window with background image and transparent listbox
by Khen1950fx (Canon) on Aug 19, 2010 at 10:19 UTC
    Yes. It's possible, but it's a lot of work. Here's an example of a transparent window with a cyan-colored circle by zentara. Reverse it and see what you can come up with.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; my $width = 100; my $height = 100; my $mw = MainWindow->new(-background => 'cyan' ); #$mw->geometry($width.'x'.$height.'+300+300'); $mw->geometry('500x500+300+300'); #$mw->overrideredirect(1); my $zinc = $mw->Zinc(-width => $width, -height => $height, -reshape => 1, #clips zinc -fullreshape => 1, #clips $mw and xterm -backcolor => 'blue', )->pack; my $petal = $zinc->add('curve',1,[[$width/2,0], [2*$width,0, 'c'], [2*$width,$height, 'c'], [$width/2,$height], [-$width,$height, 'c'], [-$width,0, 'c'], [$width/2,0]], -tags => ['bezier1'], -filled => 1, #-fillcolor => 'cyan', #attempt at semi-transparency -fillcolor => "=radial 0 0 |yellow;40|black;40 50|cyan;40", + -closed => 1, -linewidth => 0, -priority => 1, -visible => 1, ); # using the triangulaire curve to reshape both TkZinc and Mainwindow w +idgets $zinc->itemconfigure(1, -clip => $petal); MainLoop;
    See Re: Perl TK window transparency / opacity for more information.
Re: Window with background image and transparent listbox
by zentara (Archbishop) on Aug 19, 2010 at 13:33 UTC
    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
Reaped:
by NodeReaper (Curate) on Aug 23, 2010 at 13:41 UTC
Re: Window with background image and transparent listbox
by HelAu (Initiate) on Aug 23, 2010 at 13:43 UTC
    Thanks a lot for your hints.
    I've given up the idea of making the listbox transparent (First I wanted the image centered and the transparent listbox over it) and thats the Result

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://855974]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-09-17 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (56 votes), past polls