Code below, press the validate button to see the problem with line wrap and 'newline chars' as per my original post.

#!/usr/bin/perl # #Text widget word wrap problem demo # use strict; use Tk; use Tk::TFrame; my $mw = MainWindow->new; my $big_font = $mw->fontCreate( -size => 11, -family => 'Terminal', -weight => 'bold'); $mw->title("Demo App"); my $seg1_f = $mw->TFrame(-label => 'Segment 1', -relief => 'groove', - +borderwidth => 2); my $ts_box = $seg1_f->Text(-wrap => 'word', -width => 60, -height => +6, -font => $big_font); $ts_box->grid( -padx => 4, -pady => 4, -row => 0, -column => 4, -sticky => "nsew", -rowspan => + 4); $ts_box->menu(undef); $ts_box->tagConfigure("badc", -foreground => "red", -background => 'ye +llow'); my $val = $seg1_f->Button(-text => "Validate", -command => [\&valida +te_text, 4]); $val->grid(-row => 0, -column => 3, -padx => 4, -pady => 5); $seg1_f->grid(-row => 0, -column => 0, -sticky => "nsew",-padx => 2, - +pady => 2); $mw->resizable(0,0); $ts_box->insert('end', "This is some test text with some invalid @ cha +racters"); $ts_box->insert('end', " If you click the Validate button the bad char +s &should be"); $ts_box->insert('end', " highlighted! Note that a newline character"); $ts_box->insert('end', "\n hightlights to the end of the line not just + the single"); $ts_box->insert('end', " character position. Is this a bug?"); MainLoop; # Validate the text field sub validate_text{ my $i_st; my $idx; my $cnt; my $ch; $ts_box->tagRemove('badc', '1.0', 'end'); my $wstring = $ts_box->get("1.0", "end"); $idx = length($wstring)-1; if ($idx == 0) {return(0)} $cnt = 0; while ($idx != $cnt) { $ch = substr($wstring, $cnt, 1); if (!($ch =~ /[A-Za-z0-9 \/.,=?*+]/)) { $i_st = sprintf("1.%d", $cnt); # bad char $ts_box->tagAdd('badc', $i_st); } $cnt++; } }

In reply to Re^2: Tags in TK Text widgets by colintu
in thread Tags in TK Text widgets by colintu

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.