Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Tk - text widget - delete text

by Shendal (Hermit)
on Oct 03, 2000 at 21:35 UTC ( #35149=note: print w/replies, xml ) Need Help??

in reply to Tk - text widget - delete text

Use the delete method. For example:
$txtWidget = $Window->Scrolled("Text"); $txtWidget->insert('end',"blah blah blah blah"); $txtWidget->delete('0.0','end');
This will delete all the text in your text box. If you'd like to delete just a section of it, you'll want to specify a start and end index.

This and other Tk methods are documented in the Tk perldocs.


Update: In my haste, I made a mistake. It has been corrected above. $txtWidget->delete(0,'end') should be $txtWidget->delete('0.0','end').

Replies are listed 'Best First'.
RE: Re: Tk - text widget - delete text
by softeng2000 (Novice) on Oct 03, 2000 at 22:03 UTC
    Thank you for reply
    Although, I get this:

    Tk::Error: bad text index "0" at C:/Perl/site/lib/ line 217.
    Tk callback for .frame11.frame.text
    Tk::__ANON__ at C:/Perl/site/lib/ line 217
    Tk::Derived::Delegate at C:/Perl/site/lib/Tk/ line 469
    Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/ line 311
    main::ClearList_Button at C:\Valeriy\Perl\Spiders\WebCrawler\WC3\WC33.PL line 2 14
    main::__ANON__ at C:\Valeriy\Perl\Spiders\WebCrawler\WC3\WC33.PL line 105
    Tk callback for .frame10.button
    Tk::__ANON__ at C:/Perl/site/lib/ line 217
    Tk::Button::butUp at C:/Perl/site/lib/Tk/ line 111 (command bound to event)
      Here's a more complete example:
      #!perl -w use strict; # always use Tk; my $Window = MainWindow->new(-title => "Test Window"); my $uframe =$Window->Frame() ->pack(-side => 'top', -fill => 'both', -expand => 1); my $dframe =$Window->Frame() ->pack(-side =>'top', -fill => 'x'); my $txtWidget = $uframe->Scrolled("Text") ->pack(-side => 'top', -fill => 'both', -expand => 1); my $pasteBtn = $dframe->Button(-text => "Paste", -command => sub { $txtWidget->insert('end',"blah b +lah") }) ->pack(-side => 'left'); my $clearBtn = $dframe->Button(-text => "Clear", -command => sub { $txtWidget->delete('0.0','end') } +) ->pack(-side => 'left'); MainLoop();


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://35149]
sn1987a takes a cookie from the platter on the sideboard.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-26 16:06 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (484 votes). Check out past polls.