#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::WinPhoto; use Tk::PNG; my $mw = tkinit; my $width = 500; my $height = 700; my $canv = $mw->Canvas(width => $width, height =>$height)->pack(); #set cell size adjustment my $x = 50; my $y = 20; my $rows = int( $height / $y + 1 ) - 1; #make it 0 based my $cols = int( $width / $x + 1 ) - 1; print "rows->$rows cols->$cols\n"; my %cells; foreach my $row ( 0 .. $rows ) { foreach my $col ( 0 .. $cols ) { $cells{$row}{$col}{'rect'} = $canv->createRectangle( $col * $x, $row * $y, $col * $x + $x, $row * $y + $y, #-width => 1, -outline => 'white', ); $cells{$row}{$col}{'text'} = $canv->createText( $col * $x + $x/2 , $row * $y + $y/2, -text => "$row - $col", -anchor => 'center', -fill => 'black', ); } } my $canvbutton = $mw->Button(-text=>'Canvas Capture', -command => \&canv_capture, )->pack; MainLoop; ########################################################## sub canv_capture{ my $image = $mw->Photo(-format => 'Window', -data => oct($canv->id) ); my $pathname = './canvas.'.time.'.png'; $image->write($pathname, -format => 'PNG'); } ##############################################################