• Publicidad

Cómo usar correctamente Tk::Animation

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Cómo usar correctamente Tk::Animation

Notapor BigBear » 2010-04-16 18:01 @792

Hola. Ando teniendo una duda, porque quiero usar un gif animado que se comience a mover cuando le de clic a un botón pero lo raro es que no da errores pero el gif ni se mueve.

Código
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use Tk;
  2. use Tk::Animation;
  3.  
  4. my $mw = MainWindow->new;
  5. $mw->title("Animated GIF");
  6.  
  7. my @gif_files = "tigre.gif";
  8.  
  9. my $animate = $mw->Animation;
  10.  
  11. for (@gif_files) {
  12.     $animate->add_frame(
  13.         $mw->Photo( -file => $_ )
  14.     );
  15. }
  16.  
  17. $animate->set_image(0);
  18.  
  19. my $lab   = $mw->Label( -image => $animate )->grid;
  20. my $start = $mw->Button(
  21.     -text => 'Start',
  22.     -command => [ $animate => 'start_animation', 500 ]
  23. )->grid;
  24. my $stop = $mw->Button(
  25.     -text => 'Stop',
  26.     -command => [ $animate => 'stop_animation' ]
  27. )->grid;
  28.  
  29.  
  30.  
  31. MainLoop;
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4


¿Alguien me puede ayudar?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: Cómo usar correctamente Tk::Animation

Notapor explorer » 2010-04-16 18:33 @815

No lo he probado, pero no creo que necesites usar el add_frame, ya que se supone que el gif animado contiene todos los cuadros de animación.

Fíjate en el ejemplo que trae la distribución Tk:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/local/bin/perl -w
  2. use Tk;
  3.  
  4. my $mw = MainWindow->new;
  5.  
  6. use strict;
  7.  
  8. use Tk::widgets qw(Photo Animation);
  9.  
  10. my $file = (@ARGV) ? shift : Tk->findINC('anim.gif');
  11.  
  12. my $img = $mw->Animation('-format' => 'gif',-file => $file);
  13.  
  14. my $lab = $mw->Label(-image => $img);
  15.  
  16. my $start = $mw->Button(-text => 'Start', -command => ['start_animation' => $img]);
  17. my $stop  = $mw->Button(-text => 'Stop', -command => ['stop_animation' => $img]);
  18. my $quit  = $mw->Button(-text => 'Quit', -command => [destroy => $mw]);
  19. Tk::grid($lab,'-','-',-sticky => 'nsew');
  20. Tk::grid($start, $stop, $quit,-sticky => 'ew');
  21. $mw->gridRowconfigure(0,-weight => 1);
  22. MainLoop;
  23.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

Como ves, se define la animación como 'gif' y se indica el fichero gif que contiene la animación. Luego, se definen los botones (a propósito, de forma muy distinta a como los tienes tu definidos. Quizás depende de la versión de Tk que tengas instalada).
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 33 invitados