Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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.

Cheers,
Shendal

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


Comment on Re: Tk - text widget - delete text
Download Code
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/Tk.pm line 217.
    Tk callback for .frame11.frame.text
    Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 217
    Tk::Derived::Delegate at C:/Perl/site/lib/Tk/Derived.pm line 469
    Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm 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
    \&main::__ANON__
    Tk callback for .frame10.button
    Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 217
    Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm 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();

      Cheers,
      Shendal

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://35149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-11-24 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls