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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #!/usr/bin/perl
# file canvas_10_print.pl
use warnings;
use strict;
use utf8;
use Tk;
# open(IMPRIMANTE, "| lpr -Plp1") || die "Erreur d'exécution de lpr: $!";
# \\HPC4346BE4025D
# CN44H7C8BS0602
# HP Photosmart 5520 series (réseau)
#open(IMPRIMANTE, "| lpr -PLPT1") || die "Erreur d'exécution de lpr: $!";
#to change the background color, edit the ps file
# 0.000 0.000 0.000 setrgbcolor AdjustColor
# fill
my $width = 80;
my $height = 80;
my $main = MainWindow->new();
my $canvas = $main->Canvas( -width=>$width, -height=>$height, -background=>"black");
$canvas->pack( -expand=>1,-fill=>'both');
&create;
$canvas->update;
$main->update;
$main->Button(
-text => "Save",
-command => [sub {
$canvas->update;
my @capture=();
my ($x0,$y0,$x1,$y1)=$canvas->bbox('all');
@capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x0);
$canvas -> postscript(-colormode=>'color',
-file=>$0.'.ps',
-rotate=>0,
-width=>800,
-height=>500,
@capture);
}
] )->pack;
$main->Button(
-text => "Print",
-command => [sub {
open (PS, "| lpr -PLPT1"); # customize with -Pname e.g.
print PS $canvas;
close (PS);
}
] )->pack;
MainLoop;
sub create{
$canvas->createOval(10, 10, 60, 60,-fill=>'green');
} |
Partager