in reply to Very strange Scrollbar behavior in Win32 Perl/Tk version 804.027

Having tried this out, I could offer an alternative point of view: the problem is not so much with the Tk scrollbar behavior, but is rather due to an interaction between how the scrollbars work and the kind of text data you are loading into the scrolled widget.

If you add this line to the "load_url" sub, the widget behavior will be more "normal":

$text =~ s/>/>\n/g; # add this right after "my $text = $tree->as_ +HTML()"
The point is that the scrollbar slider's size is based on line count and the number of lines visible in the scrolled widget at a given moment, as well as the total percentage of text visible (or something to that effect).

If the number of text lines (i.e. the number of substrings conjoined by explicit line-feed characters) is less than the height of the Tk::Text window, but the lines are really long and get wrapped beyond the height of the window, you have a situation where the slider-sizing logic (and possibly other aspects of scrollbar behavior) will likely run into boundary conditions, or situations where "reasonable defaults" are at best much more difficult to establish and implement.

I think the exact behavior of OP code may depend on whether the html data contains any line-feeds as text content, but I'm not sure about that, just as I'm not sure yet what HTML::TreeBuilder's "as_HTML()" method does to web-page data in terms of preserving or removing line-feed characters. (Maybe that'll be explained in the docs; I just haven't looked yet.)

So, if you simply take one or two simple measures to provide a sensible concession to human readability, things will go better, because the widgets seem to have been designed with some built-in assumptions about that sort of thing.

  • Comment on Re: Very strange Scrollbar behavior in Win32 Perl/Tk version 804.027
  • Download Code

Replies are listed 'Best First'.
Re^2: Very strange Scrollbar behavior in Win32 Perl/Tk version 804.027
by liverpole (Monsignor) on Oct 29, 2006 at 16:39 UTC
    Excellent answer, and ++graff.

    Thank you very much for clearing up that mystery.  I was getting quite worried when *both* of my Perl installations were acting so bizarre.

    Apparently this is only an artifact of having huge amounts of text in a Text widget, -without- any newlines.  After applying your simple one-liner $text =~ s/>/>\n/g;, the Text widget is behaving as it should.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

      If you change line 86 of your code, to turn off wrapping:push @opts, -wrap => 'none';, you also get more normal scrollbar behaviour.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.