in reply to Updating the same line Text Widget
Also note that there is a spelling error in the perldoc for Tk::Text, deleteTextWithTag should be DeleteTextWithTag.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $update = 0; $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size => 14 ); my $text = $mw->Text(-font=>'big')->pack; $text->tagConfigure( 'updatetag', -borderwidth => 3, -background => 'yellow', -relief => 'raised', ); my $string = join ' ',('a'..'z'); foreach my $line(0..10){ $text->insert('end',"$line->$string\n"); } $text->delete("7.11", '7.13'); $text->insert("7.11", "$update ",['updatetag']); my $bFrame = $mw->Frame->pack(qw/-side bottom/); $bFrame->Button( -text => "Update Text", -command => sub { $update++; # this works, but adds spaces as $update gains characters # $text->delete("7.11", '7.13'); # $text->insert("7.11", "$update ",['updatetag']); #works good $text->DeleteTextTaggedWith('updatetag'); $text->insert("7.11", "$update ",['updatetag']); })->pack(qw/-side left/); MainLoop;
|
|---|