Hi, thanks a lot for the reply
actually I am working with text in another language,
not English text.I gave that example in my post just to
state the problem(or so I thought).I had not at all tested
with english text.

In fact my code as well works with the english text file:

x.txt try **until **you **succeed


but strangely does not work for my text file which looks
like this, if the display is set to an english font:

y.txt ]]» **]X»]» **]Eõ]» ]]»»


In this case only the first character next to the 2nd
asterisk is printed:

$result: 1.4 $start: 1.6 The word: ]

I need the whole word to be printed that is:

]X»]»


What I then need to do is change the font color of
the word so that it stands out in the widget window,
and delete the **'s.
I need to present the text in the Tk widget as a user
interface.The user clicks a button, certain words get
marked by the asterisks.But instead of the asterisks,
I now want to change the font color of the words instead.

I'm not sure how I can search within a widget window
using regexps.

here's my actual code, with a whole lot of it not relevant
to this question omitted.

#!/usr/local/bin/perl -w use Tk; #use strict; our($filename, $info); #Variables to be used in the su +bs &load_file and &save_file. #$filename stores the file name + typed by the user in the entry widget of the main window. #$info stores the text message +displayed at the bottom of the main window. my $mw = MainWindow->new; # Main window. # Create necessary widgets. my $f = $mw->Frame->pack(-side => 'top', -fill => 'x'); + #Create frame. $f->Label(-text => "Filename:")->pack(-side => 'left', -anchor => 'w') +; # Label widget. $f->Entry(-textvariable => \$filename)->pack(-side => 'left', -anchor +=> 'w', -fill => 'x', -expand => 1); # Entry widget. + #Button widgets. $f->Button(-text => "Sug", -command =>\&tged)->pack(-side => 'right'); + $f->Button(-text => "Save", -command => \&save_file)->pack(-side => 'r +ight', -anchor => 'e'); $f->Button(-text => "Load", -command => \&load_file)->pack(-side => 'r +ight', -anchor => 'e'); $f->Button(-text => "Det",-command => \&chfile )->pack(-side => 'right +', -anchor => 'e'); $f->Button(-text => "Show",-command => \&load_file)->pack(-side => 'ri +ght', -anchor => 'e'); $f->Button(-text => "Add?",-command => \&addit)->pack(-side => 'right' +, -anchor => 'e'); $mw->Label(-textvariable => \$info, -relief => 'ridge')->pack(-side => + 'bottom', -fill => 'x'); # Label widget. #Text widget. + my $t = $mw->Scrolled("Text",-font=>"{as-ttdurga} 24 {bold}")->pack(-s +ide => 'bottom', -fill => 'both', -expand => 1); MainLoop; + sub chfile { open LEX, 'soundex.txt' or die $!; my %lexicon; while(<LEX>){ chomp; my @words =split; @lexicon{@words} = (1) x @words; } close LEX; open FILE, "+<$filename" or die $!; my @missing; my @data; while(<FILE>){ push @missing, grep { ! $lexicon{$_} } split; push @data,split; } #print @missing; #print "\n@data"; seek FILE, 0, 0; # go to start of file truncate FILE, 0; foreach $ditem(@data){ $_ = process($_); print FILE; print FILE " "; foreach $mitem(@missing) { my $currentposition=tell FILE; seek FILE,0,1 ; if ($mitem eq $ditem){ syswrite FILE,"**",4 ; #print"\n$mitem"; $result=$t->search(-forwards,"**",'end'); # print"\nThe start pos of the pattern:"; # print "\n$result"; $start=$result+.2; #print "\n$start"; @chars=$t->get("$start","$start wordend"); print "\nThe word:"; print"\n@chars"; #$t->tagConfigure("wrong",-foreground=>"red"); #$t->tagAdd("wrong","$start","$start wordend"); } } } close FILE; sub process { return($ditem); } } 1;
What is the alternative to using the 'wordend' index? That does not seem to work here. Thanx

In reply to Re: Re: Tk text widget indices. by perl_seeker
in thread Tk text widget indices. by perl_seeker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.