in reply to Re: TK-Text Get text per row
in thread TK-Text Get text per row

Unfortunately, it returns the lines as defined in the original contents, not in the wrapped form:
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = 'MainWindow'->new; my $t = $mw->Text(-width => 40, -wrap => 'word')->pack; my $b = $mw->Button(-text => 'Show', -command => sub { my ($last_line) = $t->index('end') =~ /(.*)\. +/; for my $line (1 .. $last_line) { print "$line: ", $t->get("$line.0", "$lin +e.end"), "\n"; } })->pack; $t->Contents(join ' ', split /\n/, <<'EOF'); Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that it's easy to use, supports both procedural and object-oriented (OO) programming, has powerful built-in support for text processing, and has one of the world's most impressive collections of third-party modules. Different definitions of Perl are given in perl, perlfaq1 and no doubt other places. From this we can determine that Perl is different things to different people, but that lots of people think it's at least worth writing about. EOF MainLoop();

Output:

1: Perl is a general-purpose programming language ... 2:
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: TK-Text Get text per row (dlineinfo)
by Anonymous Monk on Sep 11, 2013 at 02:37 UTC

    Unfortunately, it returns the lines as defined in the original contents, not in the wrapped form:

    That makes sense, wrapping doesn't count -- it appears there is no way to retrieve the position of the wraps. You can get the space (in pixels) a line takes up with https://metacpan.org/module/Tk::Text#text-dlineinfo-index but that's about it