Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: How do I count wrapped lines in TK.::Text?

by jeorgen (Pilgrim)
on Aug 20, 2002 at 09:31 UTC ( [id://191422]=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re: Re: How do I count wrapped lines in TK.::Text?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://191422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found