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

Hi all, If we want to remove the entry widget contents we can use delete with entry object. Example $ent->delete(0,'end'); But I want to remove the Text widget contents.Can any one tell me what is the function for removing the text widget contents?
  • Comment on Delete the text widget contents using perl_tk

Replies are listed 'Best First'.
Re: Delete the text widget contents using perl_tk
by AnomalousMonk (Archbishop) on Apr 17, 2010 at 06:08 UTC
    See  *$text*->delete(*index1, *?*index2*?) in the  Tk::Text documentation. Works the same.
Re: Delete the text widget contents using perl_tk
by ungalnanban (Pilgrim) on Apr 17, 2010 at 07:33 UTC
    use the following way
    use Tk; use Tk::Text ; . . . my $txt = $mw->Text( -background =>'white', )-> pack (); . . . $txt -> delete('1.0','end');
    Refer the Links.
    Tk::Text

    --$ugum@r--
      Please, do not link to sites that break copyright.
        Ok, I removed the copyright link. Actually I don't know this.
Re: Delete the text widget contents using perl_tk
by biohisham (Priest) on Apr 17, 2010 at 18:07 UTC
    #!/usr/local/bin/perl #an index is passed to the insert method to insert text into the text +widget. #the index is passed along with the text to be inserted. #There are two general ways to specify an index for Tk: #01- use the end token. #02- specify the row.position combination. #the row is 1-based and the position is 0-based. use strict; use warnings; use Tk; my ($main, $text); $main=MainWindow->new(); $main->Button( -text=>'Type', -relief=>'raised', -command=>\&display)->pack; $main->Button( -text=>'delete', -relief=>'ridge', -command=>\&deleting)->pack; $main->Button( -text=>'exit', -relief=>'groove', -command=>[$main=>'destroy'] )->pack; $main->Button( -text=>'Position', -relief=>'raised', -command=>\&position )->pack; $text=$main->Text(-width=>40, -height=>8)->pack; sub display{ $text->insert('2.0', "Greetings\n"); #insert at the secondRow. +FirstPosition, #This only works after deleting text from the text wid +get } sub deleting{ $text->delete('1.0','2.9'); } sub position{ $text->get('2.0','1.9'); } MainLoop;


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: Delete the text widget contents using perl_tk
by vlsimpson (Beadle) on Apr 22, 2010 at 16:41 UTC

    You can pass an empty string to 'Contents' method.

     $text_window->Contents('');

    Query or change the entire contents of the text widget. If no arguments are given, the entire contents of the text widget are returned. If any arguments are given, the entire contents of the text widget are deleted and replaced by the argument list