Guest User

Untitled

a guest
Aug 12th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.94 KB | None | 0 0
  1. use Tk;
  2. use strict;
  3.  
  4. my $win = MainWindow -> new();
  5. my ($a, $b) = (325, 345);
  6. $win -> geometry("${a}x${b}");
  7. my @fill;
  8. my $cv = $win -> Canvas(-background => 'green', -height => '321', -width => '321') -> pack();
  9. for (0..31) {
  10.     my $x = $_;
  11.     for (0..31) {
  12.         my $y = $_;
  13.         my $rect = $cv -> createRectangle(2+$x*10,2+$y*10,12+$x*10,12+$y*10, -fill => 'lightgrey');
  14.         $fill[$x][$y] = 0;
  15.         $cv -> bind($rect, '<Button-1>',  [\&recolour, $rect, $x, $y]);
  16.     }
  17. }
  18. my $enx = $win -> Entry() -> place(-rely => 1.0, -y => -20, -x => 2);
  19. my $eny = $win -> Entry() -> place(-relx => 1.0, -rely => 1.0, -y => -20, -x => -127);
  20. $win -> Button(-text => 'Exit', -command => sub {exit}) -> pack (-anchor => 's');
  21. MainLoop;
  22.  
  23. sub recolour() {
  24.     if ($fill[$_[2]][$_[3]] == 0) {
  25.         $cv -> itemconfigure($_[1], -fill => 'red');
  26.         $fill[$_[2]][$_[3]] = 1;
  27.         }
  28.     else {
  29.         $cv -> itemconfigure($_[1], -fill => 'lightgrey');
  30.         $fill[$_[2]][$_[3]] = 0;
  31.     }
  32.     }
Add Comment
Please, Sign In to add comment