Re: Tk::Animation won't work :(
by JamesNC (Chaplain) on May 13, 2005 at 17:23 UTC
|
use Tk;
use Tk::Animation;
use strict;
my $scr = new MainWindow;
$scr->configure(-background=>"black");
$scr->geometry("500x500");
my $canvas = $scr->Canvas(-width,500,-height,500,
-background=> "black")->pack(-expand, 1, -fill, 'both');
my $image = $scr->Animation('-format' => 'gif', -file => "tree.gif");
$canvas->createImage( 250,250, -image=> $image);
$image->blank($image,1);
$image->start_animation(40);
MainLoop;
JamesNC
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
Re: Tk::Animation won't work :(
by zentara (Cardinal) on May 13, 2005 at 18:21 UTC
|
Here is another example, in case you don't want to use a Canvas:
#!/usr/bin/perl -w
use Tk;
use Tk::widgets qw/Photo Animation/;
use strict;
my $mw = MainWindow->new;
my $animate;
if (@ARGV) {
$animate = $mw->Animation;
foreach (@ARGV) {
$animate->add_frame($mw->Photo(-file => $_));
}
} else {
my $gif89 = Tk->findINC('anim.gif');
$animate = $mw->Animation(-format => 'gif', -file => $gif89);
}
$animate->set_image(0);
my $lab = $mw->Label(-image => $animate);
my $start = $mw->Button(
-text => 'Start',
-command => [$animate => 'start_animation', 500]);
my $stop = $mw->Button(
-text => 'Stop',
-command => [$animate => 'stop_animation']);
my $quit = $mw->Button(
-text => 'Quit',
-command => \&exit);
$lab->grid(-column => 1, -sticky => 'nsew');
$start->grid($stop, $quit, -sticky => 'ew');
$lab->gridRowconfigure(0,-weight => 1);
MainLoop;
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |
Re: Tk::Animation won't work :(
by zentara (Cardinal) on May 13, 2005 at 19:28 UTC
|
Being a Friday afternoon, I just had to see if an animated gif could be read from -data. :-) It can, and makes a nice indicator.
#!/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 =
'R0lGODlhEAAQAPEEAAAAAP8AAP//AP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAEA
+CwAAAAA
EAAQAAADPki63B4wOhWrZFYEfWm2SwCMZDkGiglsajqU2viOablBJkVCnHhSGoFgYBGhgM
+Me7ugR
KlfM0DPaqKwmWEcCACH5BAUKAAQALAEAAAAPAA8AAAM8SKrR+ysA0CokM1cXwcjUxoCZYF
+oNOZ1O
BQqTGAiVScebMOwnWdsuj6ZB26gYmxQJmZRkIE5j4EKQJB8JACH5BAUKAAQALAEAAQAOAA
+4AAAM3
SBoMzioy4cYLMojgOsOTQHXAFw4baZ7NtYap9prU1ryezZnqR+wcgKXU+O1IRMwi2ItkPE
+pCAgAh
+QQFCgAEACwBAAEADwAPAAADO0ga3KyQNEEZCHGKYYFfzhZ4wHBJFyOSJOGFAvs6aszSMI
+nfnrDL
gMpjRDJdhBjUjRaRMSOuWQOaeVATACH5BAUKAAQALAEAAQAOAA4AAAM2SBoB/Coy9wST7Q
+XB79Tb
0H2gaFkNQG2TmqqUBc/A4AqzTQMy/e4wEAMFImhOxYUQEiGsNJEEACH5BAUKAAQALAAAAQ
+APAA8A
AAM8SErRDW2tAB2o8l7Hg9Ja5xDgxgnWNZiB4KIP2ApDDafzjTKpIEcOV8nEyw0hig5o5Z
+lwSpLk
Exl1RiQJACH5BAUKAAQALAEAAQAOAA4AAAM4SBoBzkFJ5ipgk9qGrx4PB2khBQlNCXmBAK
+BjjF5C
HY8VM9jxJuywlaUGIwhzxUUK9MJIjCmWJAEAIfkEBQoABAAsAAAAAA8ADwAAAz1IutGxUL
+kGaiQz
1A2z3sCDNYLwDeDjlODmCdUXZ1vpOa3ttYBOAQReYGCiqACoGDGjSA19nVCgVBR1bosEAD
+s=';
return $gif;
}
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |
|
|
| [reply] |
Re: Tk::Animation won't work :(
by Popcorn Dave (Abbot) on May 13, 2005 at 16:35 UTC
|
| [reply] |
Re: Tk::Animation won't work :(
by tphyahoo (Vicar) on May 13, 2005 at 16:04 UTC
|
1) Maybe obvious but... did you
use warnings;
use strict;
in your program?
2) What if you just do a regular gif, not an animation, that work?
3) What about specifying the full file path instead of just "file.gif"? | [reply] [d/l] |
|
|
Thanks for the reply. Alas, I always use strict and warnings, and I've tried a plain gif. Didn't work.
| [reply] |
Re: Tk::Animation won't work :(
by davidrw (Prior) on May 13, 2005 at 16:45 UTC
|
Along w/Popcorn Dave's thoughts, i also am supsicious that the widget is not being packed/displayed properly.. On thing that might be contributing (though i still couldn't get a working version after hardcoding 500's) is that $scr->width and $scr->height are both returning 1, even after the ->geomerty() call. | [reply] [d/l] [select] |
|
|
You're right about the geometry thing. Let me rephrase:
my $scr = new MainWindow;
$scr->FullScreen(1);
$scr->configure(-background=>"yellow");
my $canvas = $scr->Canvas(
-background=>"blue",
-width=>$scr->width,
-height=>$scr->height
)->pack( -side=>"top" );
my $tree = $canvas->Animation(
-format => 'GIF',
-file => 'tree.gif'
)->start_animation( 20 );
This yields a blue screen, not a yellow one, with nothing on it. I'm not sure how the pack syntax should be for Animation..? The pod remains silent on the issue... | [reply] [d/l] |
Re: Tk::Animation won't work :(
by kwaping (Priest) on May 13, 2005 at 16:18 UTC
|
This is just a shot in the dark, as I don't have Tk installed and have never used it, but did you try removing the single quotes around '-format'? I know that's exactly how it is in the perldoc for Tk::Animation, but maybe it's a typo or oversight by the author. | [reply] |
|
|
Mmmmm... still won't work. Thanks though.
| [reply] |