Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

HELP! Tk::Error using Tk::Animation

by mikasue (Friar)
on Dec 29, 2007 at 08:57 UTC ( #659458=perlquestion: print w/replies, xml ) Need Help??
mikasue has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Tk::Animation but keep hitting this error. Can any monk provide insight on what i'm doing incorrectly? Thanks!
sub PlayAnimation{ my $animation_toplevel = $main::mw->Toplevel; my $img1 = $animation_toplevel->Photo(-file=>$Bin."/MMD/images/spinnin +gpenny.gif"); my $img = $animation_toplevel->Animation(-format => 'gif', -file =>$im +g1)->start_animation(10); my $anibut = $animation_toplevel->Button(-image=>$img, -command=>sub{p +rint"You pressed me!";})->pack; }
Error i'm getting
Tk::Error: Cannot open 'image3' in mode 'r' at C:/Perl/lib/Tk/ + line 21. Tk callback for .toplevel1 Tk callback for image Tk::Image::new at C:/Perl/lib/Tk/ line 21 Tk::Animation::new at C:/Perl/lib/Tk/ line 26 Tk::Widget::__ANON__ at C:/Perl/lib/Tk/ line 256 MMD::PROGRAMDEFAULTS::PlayAnimation at C:/Documents and Settings/Owne +r/My Docum ents/pianokeys/MMD/ line 105 main::__ANON__ at line 74 Tk callback for .toplevel.canvas.button Tk::__ANON__ at C:/Perl/lib/ line 252 Tk::Button::butUp at C:/Perl/lib/Tk/ line 111 <ButtonRelease-1> (command bound to event)

Replies are listed 'Best First'.
Re: HELP! Tk::Error using Tk::Animation
by eserte (Deacon) on Dec 29, 2007 at 09:43 UTC
    The value for Tk::Animation's -file option has to be a file name, not an image reference.
Re: HELP! Tk::Error using Tk::Animation
by zentara (Archbishop) on Dec 30, 2007 at 16:42 UTC
    If you want to save yourself the hassle of including separate gif files, you can inline them.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Animation; my $scr = new MainWindow; $scr->configure(-background=>"black"); $scr->geometry("200x100"); 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($image,1); $image->start_animation(40); MainLoop; sub get_gif{ #base64encoded gif89a 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. Cogito ergo sum a bum

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-06-24 05:25 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.