in reply to Updating the same line Text Widget

I made a little example for you, to show the difference between using indices and tags for doing the delete and insert. Tags work much better, because it tags the entire length of the inserted word, making inserts cleaner.

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;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh