in reply to Printing a TK Canvas

Well that information is earlier in the script, where the sub is called. If you look at the widget demo, for plot, you should be able to see where it's called. However, I have to agree that the demos are written by people who are good, and take alot of "code shortcuts" which are hard for beginners to see.

So rather than try to explain to you, what you can find yourself, I will give a "more straight-forward" example.

Like in kvale's first reply, you need to specify the "boundaries" of what you want to capture as postscript. That is what the $pinfo is for. So look at this simple example.

#!/usr/bin/perl use Tk; #to change the background color, edit the ps file # 0.000 0.000 0.000 setrgbcolor AdjustColor # fill $width = 800; $height = 500; my $main = MainWindow->new(); my $canvas = $main->Canvas( -width=>$width, -height=>$height, -backgro +und=>"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-$x +0); $canvas -> postscript(-colormode=>'color', -file=>$0.'.ps', -rotate=>0, -width=>800, -height=>500, @capture); } ] )->pack; MainLoop; sub create{ $canvas->createOval(100, 100, 600, 600,-fill=>'green') }

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re: Re: Printing a TK Canvas
by Anonymous Monk on Apr 18, 2004 at 18:53 UTC
    wow, thanks for that :) i didnt know about that widget demo thing, its very useful :)

    It all appears to work now, my canvas prints to postscript form, almost perfectly! the biggest thing which would go on it, is luckily in perfect proportions for an A4 sheet! The only problem i am still having is with the lpr command...

    lpr -S localhost or 127.0.0.1 -P LPT1 FILENAME

    which its having problems with (Error: print server unreachable or specified printer does not exist.). Howevetr im sure its only a matter of time before i work this out! And the fact it is getting this far anyway means that it is likely to work once it finds te correct place! :)

    Thanks alot!

      The reason You're having problems with:

      lpr -S localhost or 127.0.0.1 -P LPT1 FILENAME

      Is that under WinXP (which you mention running), you need to enable lpr support under "services". Please note that lpr support is only available under XP-Pro, NOT under XP-Home.

      And even then it's kludgy and hard to administer. It's easier to just dump into a file and spawn (Win32::CreateProcess()) something to do the dirty work of sending it to the printer, like maybe, ghostscript.


      madams55075@comcast.net