1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/local/bin/perl
use Tk;
my $x0,$y0,$x1,$y1;
$x0 = 10;
$y0 = 150;
$x1 = 100;
$y1 = 250;
my $mwin = new MainWindow;#Create the Main Window
my $canv = $mwin -> Canvas(-relief=>"sunken", -background=>"black",-confine=> 1);
$canv -> create('rectangle',$x0,$y0,$x1,$y1, -outline=>"white",-dash=>[2,4,2,4], -tags=>"rect01");
$canv -> pack;
 
## Animating The Square.
$mwin -> bind("<Left>", sub{
                            $x0 -= 8;
                            $x1 -= 8;
                            $canv->coords("rect01",$x0,$y0,$x1,$y1 )});
$mwin -> bind("<Right>", sub{
                            $x0 += 8;
                            $x1 += 8;
                            $canv->coords("rect01",$x0,$y0,$x1,$y1)});
$mwin -> bind("<Up>", sub{
                            $y0 -= 8;
                            $y1 -= 8;
                            $canv->coords("rect01",$x0,$y0,$x1,$y1)});
$mwin -> bind("<Down>", sub{
                            $y0 += 8;
                            $y1 += 8;
                            $canv->coords("rect01",$x0,$y0,$x1,$y1)});
$mwin -> bind("<Button-1>", sub{
                            $x0 = 10;
                            $y0 = 150;
                            $x1 = 100;
                            $y1 = 250;
                            $canv->coords("rect01",$x0,$y0,$x1,$y1)});
MainLoop;