You are experiencing some common mistakes which are encountered when trying to make animated guis. Here is your script, with just a few changes, and it does what you probably want. A few tips. Never use sleep in a gui program. Never setup for loops with delays in them. Your modified program works, but there is probably a better way to do it, like
#!/usr/bin/perl use warnings; use strict; use Tk; my $top=MainWindow->new(); my $canvas=$top->Canvas(width=>300, height=>245)->pack(); my $origin_x=110; my $origin_y=70; my $PI=3.141592635; my $circle_radius=5; my $path_radius=0; my $angle = 0; &animate(); $top->Button(-text=> 'Again', -command=>\&animate)->pack; MainLoop(); sub animate{ $canvas->delete('circles'); $origin_x=110; $origin_y=70; $circle_radius=5; $path_radius=0; $angle = 0; my $repeater; $repeater = $top->repeat(500, sub{ $path_radius+=7; $circle_radius+=3; $angle+=10; my $path_x=$origin_x+$path_radius*cos($angle*$PI/90); my $path_y=$origin_y-$path_radius*sin($angle*$PI/90); $canvas->create('oval', $path_x-$circle_radius, $path_y-$circle_radius, $path_x+$circle_radius, $path_y+$circle_radius, -fill=>'yellow', -tags => ['circles'], ); $canvas->create('line', $origin_x, $origin_y, $path_x, $path_y, -fill=>'slategray', -tags => ['circles'], ); if( $angle > 180 ){ $repeater->cancel } } ); }
#!/usr/bin/perl use Tk; $top=MainWindow->new(); $canvas=$top->Canvas(width=>300, height=>245)->pack(); $origin_x=110; $origin_y=70; $PI=3.141592635; $circle_radius=5; $path_radius=0; $top->waitVisibility; for ($angle=0; $angle<=180; $path_radius+=7, $circle_radius+=3, $angle ++=10) { $path_x=$origin_x+$path_radius*cos($angle*$PI/90); $path_y=$origin_y-$path_radius*sin($angle*$PI/90); $canvas->create('oval', $path_x-$circle_radius, $path_y-$circle_radius, $path_x+$circle_radius, $path_y+$circle_radius, -fill=>'yellow'); $canvas->create('line', $origin_x, $origin_y, $path_x, $path_y, -fill=>'slategray'); $top->after(500); $top->update; } MainLoop();

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Animation Display appling Delay and Canvas Object by zentara
in thread Animation Display appling Delay and Canvas Object by Alex Chew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.