Thanks for your reply, and your code graff!

All I really need is a function that gives me the number of display  lines of the (proportional font) text in the widget if the widget had enough height, not logical lines if the widget had infinite width. I suspect there might be something like that in the layout functions of Tk, but alas, I do not understand things that deep down as yet.

graff writes:
The easiest way (which can tend to make the text hard to read at runtime) is to set the text widget for character wrapping (as opposed to no-wrap or word-wrap), keep a fixed width for the widget (say, 40), and divide the string length by that width to decide how many lines are needed. 

I want to be able to use a proportional font, you see... I should have written that. And I want to use word wrapping. It was very late here (CET) when I posted so I did not  describe the problem concisely enough.

I've added a little to your example to demonstrate using string length to configure widget dimensions. But I have to admit there are things I don't get, like why you have a set of smaller unscrolled text widgets in a bigger scrolled one, or how the "print_info" is expected to help things.

Each widget will hold a paragraph an be editable remotely by a another user. Print info is there just to demonstrate that the yscroll would be perfectly usable for expandning the window to the right size (by dividing the current height of the widget with the yscroll value, and this should work with proportional text as well), but not to shrink it accordingly. The index value demonstrates that the number of lines counted are logical lines, not display lines. Again, some better labelling and some number crunching in that fucntion would make that less cryptic.

 

/jeorgen


In reply to Re: Re: How do I count wrapped lines in TK.::Text? by jeorgen
in thread How do I count wrapped lines in TK.::Text? by jeorgen

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.