ChrisR has asked for the wisdom of the Perl Monks concerning the following question:

I have been working on my first Tk app and have run into a snag. I need to be able to copy the contents of a canvas widget to the clipboard. A super search on perlmonks for canvas clipboard returned nothing. Searching on google returned a lot of stuff but nothing that helped me (at least not with this problem). From what little I have learned, I need to do:
$canvas->clipboardClear; $canvas->clipboardAppend(-format=>'BITMAP',-type=>'BITMAP',?--?,data);
My problem is that I have no idea what needs to go in place of the "data" so that it will use the contents of the canvas.

In place of "data", I tried using $canvas and \$canvas which returned no errors but of course didn't work either. I also tried assigning the return of $canvas->find('all') to a variable and using that in place of "data". Again, a miserable failure.

I'm sure that I have simply over looked something terribly obvious but I just can't seem to find the answer. Any help, examples, or links would be greatly appreciated.

Thanks,
Chris

Replies are listed 'Best First'.
Re: Tk canvas to clipboard
by TedPride (Priest) on Nov 01, 2004 at 21:44 UTC
    Maybe this will help?

    ----

    -clipboard
    The clipboard option can be used with the Capture and MetaFile commands to place copies of widget windows on the clipboard. The format of the clipboard option is as follows:

    ... -clipboard boolean

    where boolean indicates that the image or metafile is to be written to the clipboard if its value is "true", "yes" or "1". By default, images or metafiles are not written to the clipboard.

    ----

    From page:
    http://pages.infinit.net/cclients/files/tkprint1.1.html

Re: Tk canvas to clipboard
by zentara (Cardinal) on Nov 02, 2004 at 13:48 UTC
    What exactly are you trying to copy from the canvas, a screenshot of it's contents?

    I couldn't find the clipboardClear or clipboardAppend methods in perldoc Tk::Canvas, so I think you are thinking about this wrong. Maybe you think it is like Gimp, where you can select rectangular regions and save them as graphics to a clipcoard?

    The only thing I've seen used is to capture the entire canvas as postscript, or use Win::Photo to capture as a jpg, or png,etc.

    The only one which allows you to select coordinates is postscript, and you might be able to select a region, with a mouse drag, and substitute the values into something like the following code:

    $mw->Button( -text => "Save PS", -command => [sub { $canv->update; my @capture=(); my ($x0,$y0,$x1,$y1)=$canv->bbox('all'); @capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x +0); $canv->postscript(-colormode=>'color', -file=>$0.'.ps', -rotate=>0, -width=>2400, -height=>3400, @capture); } ] )->pack;
    You need to show us some code of what you are actually trying, because we are just guessing at what you want.

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