ldln has asked for the wisdom of the Perl Monks concerning the following question:

The scrollbars in the Tk::Text widget does not seem to work as they should in following script:

use strict; use Tk; my $mw = MainWindow->new(); my $t = $mw->Scrolled('Text',-scrollbars=>'e',-wrap=>"word")->pack +; $t->insert("end"," this is a test" x 4000); MainLoop;
When I scroll halfway down into the text and press return to insert newlines into the widget, the scrollbars start to resize until they fill the entire scrollbar-box. When I then scroll up and down in the text the scrollbar is behaving crazy, resizing itself as I scroll past the newlines..

Is there any way to prevent this from happening?

I'm on win32 with perl 5.8.4-810 and Tk 804.027

Replies are listed 'Best First'.
Re: Tk::Text scrollbar resize problem
by kvale (Monsignor) on Oct 20, 2004 at 19:03 UTC
    The reason the scrollbars 'go crazy' is that you have created one enormously long line. When you add lines and scroll through them, the scrollbars change size accoring to the fraction of lines shown in the window. At the top, you are only showing a part of one line. But in the blank line areas, you are showing many.

    To get a better behaved scrollbar, split your input into lines:

    use strict; use Tk; my $mw = MainWindow->new(); my $t = $mw->Scrolled('Text',-scrollbars=>'e',-wrap=>"word")->pack; $t->insert("end"," this is a test\n" x 4000); MainLoop;

    -Mark

      Thanks for reply.

      Yes, I use a long line in the example to illustrate the problem. In my app I have several long lines, with variable lenghts, that are inserted into the text widget. When I scroll up and down the scrollbar resizes itself, going from small to big, back and forth.. It doesn't look very nice at all :/.. If I start splitting the text I loose the orginal formatting of the text, which will cause problems cos I copy the text from another widget and display it in a small toplevel "popup window" with a text widget - which is then going to be edited and inserted back into the orginal widget when the toplevel window closes.

      It's a damn shame the scrollbars behave like this.. Can't see the logic in why they should resize themselves according to the fraction of lines shown..

      Well, It's normal procedure again I guess. 30 minutes to get the basic Tk functionality up and running, then 3 days to work around all the anomalies :(

Re: Tk::Text scrollbar resize problem
by Courage (Parson) on Oct 20, 2004 at 20:10 UTC
    This is known limitation of Text widget in Tcl/Tk, and TIP155 proposes to fix this in Tcl/Tk, see http://www.tcl.tk/cgi-bin/tct/tip/155.html

    Text is misbehaving in Tcl/Tk version 8.4, but behaves correctly in beta-version 8.5, so Tcl/Tk developers implemented that TIP.
    (I just tried this -- I downloaded ActiveTCL 8.5 beta and checked this behaviour)

    http://search.cpan.org/~vkon/Tcl-Tk-0.84 module from CPAN allows you to use Tcl/Tk from Perl with PerlTk syntax.
    addition: ... so you can write normal code today and expect sooner or later for it to behave better after upgrading of module...

    Best regards,
    Courage, the Cowardly Dog