Arjen Markus wrote:
> On 7 feb, 10:48, Rob <dislexic_wob...@NOSPAMyahoo.com> wrote:
>> I have written the following code which reproducibly causes a strange
>> result. The text string used as input is actually 176 characters long
>> (according to the 'string length' command). Just in case it matters, this
>> text string contains with no internal line breaks.
>>
>> text .txt -width 55 -wrap word
>> label .lbl -bg cyan3
>>
>> pack .lbl -side top -fill x
>> pack .txt -side left
>>
>> set comment "Science fiction author, journalist, and all around futurist
>> Cory Doctorow believes the recent copyright battles are the opening salvo
>> of a larger war against general computers."
>>
>> When the 'update idle' line of code is *not* used, the output from the
>> puts statement is 176. When the update line IS used, the result is 4.
>>
>> Given that I was trying to get the count of the display lines produced,
>> these outcomes are confusing. From the visual evidence (text box), 4 is
>> obviously the correct outcome.
>>
>
> While I am not sure why you get 176 as the outcome of the program
> _without_ the "update idle" command, I do understand why there is a
> difference. You get similar problems/variations when you try to
> create a PostScript file with the contents of a canvas.
>
> The thing is that the text widget has not been able to fully
> accommodate
> its contents with respect to the available geometry. Quite possibly,
> as with the canvas, it has to assume that its size is minimal (in this
> case: one character wide) until it can negotiate with the containing
> widget what its size will be.
>
> The "update idle" command causes this negotiation to occur rightaway.
> Once it is done, the text widget can properly compute how many
> characters
> it can show at each display line.
Arjen
Thank you for the explanation. The 176 characters is the length of the input
string, so I was concerned that somehow the text widget was reverting to
counting the number of characters rather than the number of display lines
which I actually requested - so maybe a bug of some sort!
What you've said explains the behaviour perfectly. Should a warning that
this sort of behaviour might occur be put into the documentation so a
developer using the text widget is prepared for what looks like a
behavioural problem (but as you've pointed out, is not!)? And the use of the
"update idle" command as a 'work around'.
Rob