Tk copy to mouse clipboard
zentara
created: 2006-03-11 10:38:15
Tk has had a problem, in programatically trying to set strings into the handy mouse clipboard. Tk::Clipboard didn't work as it should. Then when you tried to copy from a text box with selectAll, a nasty newline would always be added. Very crude. I found by methodical hacking attempts, how to strip the newline.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;

# a "phantom newline"-free copy'n'paste to 
# the mouse clipboard 

my $mw = tkinit;
                           
my $textbox = $mw->Text(); #never packed 
                           
$mw->Button(-text =>'CLipAppend',
            -command=>sub{
              $textbox->clipboardClear;
              $textbox->delete('1.0','end');
              $textbox->insert('end','foobarz');
              $textbox->selectAll;
              #this next line must come after the selectAll      
              $textbox->delete('end - 1 chars','end');
              $textbox->clipboardColumnCopy;
              print chr(07); #beep 
              })->pack();

MainLoop;

perlmonks.org content © perlmonks.org and zentara

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03