Tkinter: How to get Label wraplength functionality in Text Box

Guilherme Polo ggpolo at gmail.com
Tue Oct 28 19:51:35 EDT 2008


On 10/28/08, Mudcat <mnations at gmail.com> wrote:
> I've tried quite a few things to get this correct but have hit a
>  couple of sticking points that I can't figure out. I need to ge the
>  Text box to function like the 'wraplength' option in a Label.
>
>  I've been able to adjust the height of the text by calculating the
>  number of lines needed to display the text. That's fairly simple. I
>  know the number of characters in the text and width of the box (which
>  is static). From that point I can calculate how many lines of display
>  is needed and resize it.
>
>  The problem arises when I use the 'wrap' option of the Text Box so the
>  words aren't chopped off. Once the wrapping is done there are dead
>  spaces left at the end of the lines which are ignored when the char
>  count is done. As a result sometimes the last line is not shown. I can
>  always just add +1 to the number, but then sometimes I get an empty
>  line. Space is at a premium in this app, so I have to cut everything
>  down to use only what's necessary.
>
>  So does anyone know how add in those extra spaces to get this to
>  adjust correctly? (Or if there is another way to get the Text Box to
>  automatically adjust it's size that I'm not aware of?)
>

Are you looking for something like the new "count" command for the
text widget in tk 8.5 ? "count" can count the number of logical lines
(irrespective of wrapping), display lines (counts one for each time a
line wraps) and some other things.


>  Thanks
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves



More information about the Python-list mailing list