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

Hi I need to reset the text of a text widget so it wont hold the previous value. I m stuck there with no solution
my $addbutton = $frm_name3 -> Button(-text=> "Prosthesi",-command>\&pu +sh_button) ->pack(-side=>'left'); $txtapitimhsh = $frm_name4 -> Text(-width=>8, -height=>1) ->pack(-side=>'right'); sub push_button { @totalmetoxwn = 0; push(@totalmetoxwn,$telikitimh); foreach (@totalmetoxwn) { $sunolometoxwn += $_ ; $txtapitimhsh -> insert('end',$sunolometoxwn); #here i get th +e previous value and the new one }
Any help very appreciated

Replies are listed 'Best First'.
Re: reseting text widget
by liverpole (Monsignor) on Dec 12, 2006 at 23:40 UTC
    Hi props,

    I think what you're asking for is how to delete the contents of a Text widget.

    That's easy ... use the delete method.  For example:

    $txtapitimhsh -> delete('1.0', 'end');

    The above code means to delete from the first line, zeroth character ('1.0') to the end of the Text widget (which can, of course, be multiple lines long).

    Here's your program with a few corrections made so that it would run, and with use strict; and use warnings; (which are usually a good idea ;-)):

    use strict; use warnings; use Tk; my @totalmetoxwn = ( ); my $telikitimh = 100; my $sunolometoxwn = 0; my $mw = new MainWindow; my $frm_name3 = $mw -> Frame() -> pack(); my $frm_name4 = $mw -> Frame() -> pack(); my $addbutton = $frm_name3 -> Button(-text => "Prosthesi", -command =>\&push_button); $addbutton->pack(-side=>'left'); my $txtapitimhsh = $frm_name4 -> Text(-width=>8, -height=>1); $txtapitimhsh -> pack(-side=>'right'); MainLoop; sub push_button { @totalmetoxwn = ( ); push(@totalmetoxwn, $telikitimh); foreach (@totalmetoxwn) { $sunolometoxwn += $_ ; #here i get the previous value and the new one $txtapitimhsh -> delete('1.0', 'end'); $txtapitimhsh -> insert('end', $sunolometoxwn); } }

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Thank you liverpole