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

Hi All, Can I Use Ctrl A and del in the Entry widget for deleting the entire content in the widget? If "yes", How we can achive this? If "No", please suggest any work around for achieving the same. Thanks

  • Comment on Using Ctrl A and del in the Entry widget in perl tk

Replies are listed 'Best First'.
Re: Using Ctrl A and del in the Entry widget in perl tk
by zentara (Cardinal) on Oct 21, 2011 at 11:23 UTC
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; my $ent = $mw -> Entry() -> pack(); $ent->focus; $ent->bind('<Control-a>', \&clear ); $ent->bind('<Delete>', \&clear ); MainLoop; sub clear { $ent->delete(0,'end'); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      I think the OP meant "Use Ctrl+A to select the entire entry, and then Del to delete it". Or maybe not?
        Thats easy enough to accomplish, since after a selection, a Delete press will delete the selection.
        #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; my $ent = $mw -> Entry( -bg => 'white', -selectbackground => 'hotpink', ) -> pack(); $ent->focus; $ent->bind('<Control-a>', \&select_it ); MainLoop; sub select_it{ $ent->selectionRange(0,'end'); }

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: Using Ctrl A and del in the Entry widget in perl tk
by Anonymous Monk on Oct 21, 2011 at 07:01 UTC
    Sure you can, see Tk::bind, but it goes against convention