use Tk; #### #!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $mw = MainWindow->new; $mw->geometry("700x600"); my $canvas = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exit(0)}) ->pack; $canvas->createText(100,10, -text => 'Drag Red Peg to hole', -fill => 'white'); $canvas->create('oval', 300,300,500,500, -fill=>'yellow', ); my $dr = $canvas->createRectangle(0, 20, 50, 75, -fill => 'red', -tags => ['move','red'], ); $canvas->bind('move', '<1>', sub {&mobileStart();}); $canvas->bind('move', '', sub {&mobileMove();}); $canvas->bind('move', '', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $canvas->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $canvas->raise('current'); } sub mobileMove { my $ev = $canvas->XEvent; $canvas->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); my @coords = $canvas->coords('current'); } sub mobileStop{&mobileMove;}