#!/usr/bin/perl -w # Strict use strict; use warnings; # Libraries use Tk; # Subroutines sub random($) { int rand $_[0] } sub random_square($) { my $can = shift; my ($x0, $y0, $x1, $y1) = (random 256, random 256, random 256, random 256); $x1 += $x0; $y1 += $y0; my $bg = sprintf "#%02x%02x%02x", random 256, random 256, random 256; $can->createRectangle($x0, $y0, $x1, $y1, -fill => $bg); } # Main program my $mw = new MainWindow(-title => "Canvas binding test"); my $can = $mw->Canvas(-bg => 'white', -width => 512, -height => 512); $can->pack(-expand => 1, -fill => 'both'); $can->CanvasBind('', [\&random_square]); MainLoop;