Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Animation using Tkx

by Kirsle (Pilgrim)
on Nov 27, 2009 at 21:39 UTC ( #809816=note: print w/replies, xml ) Need Help??

in reply to Animation using Tkx

Try looking into the source code of Tk::Animation.

It looks like it creates a new Tk::Photo object for each index of the image, using `-format "GIF -index $index"`:

sub new { my ($class,$widget,%args) = @_; my $obj = $class->SUPER::new($widget,%args); $obj->{'_MainWIndow_'} = $widget->MainWindow; if ($args{'-format'} eq 'gif') { my @images; local $@; while (1) { my $index = @images; $args{'-format'} = "gif -index $index"; my $img; eval {local $SIG{'__DIE__'}; $img = $class->SUPER::new($widget,% +args) }; last if $@; push(@images,$img); } if (@images > 1) { $obj->add_frame(@images); $obj->{'_frame_index_'} = 0; } } $obj->set_image( 0 ); $obj->_get_gif_info; return $obj; }

Tk::Animation basically just creates a ton of Photo objects, and a label, and then with a $tk->repeat loop, it updates the label with the next image in the animation.

sub start_animation { my ($obj,$period) = @_; my $frames = $obj->{'_frames_'}; return unless $frames && @$frames; my $w = $obj->MainWindow; $obj->stop_animation; $obj->{'_period_'} = $period if $period; $obj->{'_NextId_'} = $w->repeat($obj->{'_period_'},[$obj,'next_image_ +in_animation']); }

It should be trivial to re-implement this module in Tkx. If Tkx doesn't have a "-index" option in the image's -format you may need to use an external module like Imager to split up the frames of the gif, and make a new Photo object or similar for each frame.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://809816]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2021-09-24 07:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found