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

I am not sure how to resolve the issue when you copy and paste into an entry widget. When you selected the existing text in the entry widget and do a paste (over it), it adds the text you copy and paste it to the existing text rather than overwrite the selected existing text. I do not see any Entry options in the documentation which will allow me to do this. Below is the code I have that sets up the entry widget:
my $ent3 = $frm_chapter -> Entry(-width=>3, -insertwidth => 3, -exportselection =>1) -> pack(-side => 'left', -expand => 1); # I also know that there are methods such as # $entry->selectionClear( ); # $entry->delete( ); # but how do I incorporate it to work when I paste?
Thanks in advance for your help. -Paul

Replies are listed 'Best First'.
Re: Entry Widget (copy and paste issue)
by Anonymous Monk on Sep 14, 2010 at 20:53 UTC
    Are you talking about Tk::Entry? See http://search.cpan.org/dist/Tk/pod/Entry.pod#DEFAULT_BINDINGS
    The F18 key (labelled Paste on many Sun workstations) or Control-y inserts the contents of the clipboard at the position of the insertion cursor.
    On my win32 machine, ctrl-y doesn't work, but ctrl-v does and behaves the same.

    If you want to change the behaviour, you will have to override the binding, eg

    $ent3->bind('<<Paste>>', sub { .... } );
Re: Entry Widget (copy and paste issue)
by zentara (Cardinal) on Sep 15, 2010 at 09:31 UTC
      I may be communicating my thoughts incorrectly. The copy and paste works. The problem is when I paste it, if there is already text in the entry(text box), even though I have the text in the entry(text box) highlighted, it doe not over-write it but instead it appends to it. For example, lets say I copied the text "TEXT" and I pasted it into a entry(text box) which already contains the text "NEW". The new text in the entry(text box) is now "NEWTEXT" rather than just "TEXT".
        I understood. You need to bind a sub to Paste that will overwrite the hilighted text, because the default binding will not do that, not under any circumstance
Re: Entry Widget (copy and paste issue)
by Anonymous Monk on Sep 14, 2010 at 20:32 UTC