Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Tk gif animation

by Chuma (Beadle)
on Mar 01, 2013 at 12:58 UTC ( #1021246=perlquestion: print w/replies, xml ) Need Help??
Chuma has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying out Tk::Animation, by making an example program that displays an animated gif. But the different frames have different transparent areas, and each frame is displayed on top of the previous ones.

That's no fun. What to do?

Replies are listed 'Best First'.
Re: Tk gif animation
by zentara (Archbishop) on Mar 01, 2013 at 17:52 UTC
    As far as I know, Perl Tk dosn't support transparencies. You will have to put everything on an appropriately colored background to mask the transparency. This works.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Animation; my $scr = new MainWindow; $scr->configure(-background=>"black"); $scr->geometry("200x150"); my $canvas = $scr->Canvas(-width,200,-height,100, -background=> "black")->pack(-expand, 1, -fill, 'both'); my $image = $scr->Animation('-format' => 'gif', -data => get_gif() + ); $canvas->createImage( 50,50, -image=> $image); $image->blank; my $buttonframe = $scr->Frame()->pack(-expand=>1, -fill=>'both'); my $start = $buttonframe->Button(-text => 'Start', -command => sub{ $image->start_animation(40); } )->pack(-side=>'left'); my $stop = $buttonframe->Button(-text => 'Stop', -command => sub{ $image ->stop_animation; $image ->blank } )->pack(-side=>'right'); MainLoop; sub get_gif{ #base64encoded gif89a ... Tk accepts images in base64encoded format as + -data my $gif = 'R0lGODlhIAAgAPMAAP////zzBf9kAt0IBvIIhEYApQAA1AKr6h+3FABkEVYsBZBxOsDAw +ICAgEBA QAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/h1HaWZCdWlsZGVyIDAuMSBieSBZdmVzIFBpZ3 +VldAAh +QQECgD/ACwAAAAAIAAgAEMEgxC82SS4OOvNb6sfVT1dyX1AQ6YhuZpwh7agyL5xjoFf5d +U606x3 CwZrvh1vgjNqesOm8xSdSXXWTXbKSj2iV67y9g2JlcPuuat6tizrHzn+i9Iz4F74uPx6z1 +BEW05I bn+EQBhMI1xZfXsxVnZrgZN3bCplcGKCKjOALChynImXbDgRACH5BAQKAP8ALAAAAAAgAC +AAQwSG sLUHqr04a9uAlFw3baQGfuJYrpv4dNdJndPbUewqV99D4bkgL+VzCUk74sujOupoNg/Quc +NUnUwp dIo1KXvd2Cd7pRotvmV4qE0xuWu2pDiPk2vnLmpcFrpgIVJYZWk3ekZKcH5/RHZ7UHZWX4 +ZrfBN9 fkwgcopPgpIeh589nUEykHGnIhEAIfkEBAoA/wAsAAAAACAAIABDBIywtfckeCDrzbu2Uy +ZNGOad aAeSDRCmsNiGM2m64zffMbquvF5v19qAgkLOaInD1Cq75OlljEp1LmgTeVU9odSubIXLis +thSuVy Rmsl3LYMzTLLlzW7eFLEhpNWGWotcTBHLluFMUdAcjh4TY5KXxaKi0CHe499mVKdfpYemS +MUbHtE X3c1jZJ+f44gEQAh+QQECgD/ACwAAAAAIAAgAEMEhhDI1kB7MuvNNbVURWFdaW7iU3np6W +ZhDJIZ GT4Y/e6weKkWHY/zuVhmuKEyNFv1gsrOpfiLvqi4mxXFpEK3RR0OKFymsFsXVuVMH2Xcr1 +szrpSX GN94ftbPQTF+fyxIH3dDXVMtYIBOYVaPcUZRkTc5aWFrfD5og08jbG2YekB/Mh+DZxkRAD +s='; return $gif; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Tk gif animation
by ww (Archbishop) on Mar 01, 2013 at 13:35 UTC
    Post some code, maybe, so we can see where your problems lie?

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021246]
Approved by Ratazong
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2018-03-17 06:54 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (223 votes). Check out past polls.