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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:


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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-01-28 08:22 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.