mdog has asked for the wisdom of the Perl Monks concerning the following question:

Brethern --

I'm trying to do something pretty simple...set the opacity of a Perl TK window to be transparent (would like to do it gradually so that it fades) BUT it seems there are no methods or attributes that allow for doing this.

The documentation doesn't mention anything for windows and my internet searches yieled one other person trying to do this and failing.

Anyone else have any ideas or is it just not possible?

Many thanks,
mdog

Replies are listed 'Best First'.
Re: Perl TK window transparency / opacity
by vkon (Curate) on Jun 30, 2006 at 17:48 UTC
    impossible with perl/Tk but possible with Tcl::Tk or Tkx or Tcl

    perl/Tk is trimmed version of Tcl/Tk, so many things are impossible compared to Tcl/Tk

Re: Perl TK window transparency / opacity
by jdtoronto (Prior) on Jul 01, 2006 at 01:18 UTC
    It is in fact not impossible on Perl/Tk. But it is by no means trivial. I recall on one of the Tk lists some time back that there was a report of how it ccould be achieved, but I dont seem to have it archived here. You need to be able to play with the Win32::API at the same time and finding the hooks manage the windows is not easy.

    If this is something you need to do routinely then look at something like Tcl::Tk, it may be possible in WxPerl as well, it would be worth investigating. Try http://wxperl.org for more information.

    jdtoronto

Re: Perl TK window transparency / opacity
by zentara (Cardinal) on Jul 01, 2006 at 13:02 UTC
    I think you might be better off with Tk::Zinc than plain Tk. I played around a few years ago, without much useful success. On linux, it depends on the WindowManager features. You may be more ingenious than me. It's been awhile since I read the docs with a fine toothed comb, but I seem to think that alpha levels are not supported when clipping( making the xterm transparent).
    #!/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;

    If you wanted to do everything on a Zinc Canvas, you could simulate it. Here is some alpha stuff


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Perl TK window transparency / opacity
by mikasue (Friar) on Jun 30, 2006 at 17:39 UTC
    mdog when you say "window" are you speaking of the main window? a frame? another widget that contains other widgets? It is really hard to set the transparency of one widget and then other widgets are in that widget. Please clarify what you are wanting to fade.
      Hey mikasue --

      Sorry, about the lack of specficity...I must have had a "user" moment there.

      I meant the main window in particular but am curious about any widget.

      Thanks,
      mdog