G'day nitep70,

Welcome to the Monastery.

I find the autoscroll package handles all types of scrolling cleanly. The basic Tkx code looks like this:

Tkx::package_require('autoscroll'); ... # Automatically mapped scrollbar Tkx::__autoscroll__autoscroll($sb); ... # Fixed scrollbar Tkx::__autoscroll__unautoscroll($sb);

There's a CPAN module, Tkx::Scrolled, which emulates this. You might like to look at its source code to get a few ideas. Be aware, by its own admission: "... we kludge it ..." (see its comments before the '_set' subroutine).

In the code you've posted, some of your g_grid() option values look dodgy. A vertical scrollbar should be "-sticky => 'ns'": you have "-sticky => 'nsew'". Your scrollbar and sizegrip both have "-column => 3, -row => 4": that doesn't look right.

I'm also wondering about text in a canvas widget: a listbox widget seems more appropriate for the scenario you describe.

If you tidy up your code, it will be easier for you to read and less prone to errors. It wasn't a pleasure for me to read: I may have missed things. You can get some hints from perlstyle; also see perltidy — the choice of code layout is yours but, when you have chosen, use it consistently.

There may be other areas that could be improved; however, this code at the start stood out:

my @results=(); my @id6=(); for my $i(0..100) {$results[$i] = 2*$i;} &do_canvas4;

I probably would have written that more like:

my @results = map 2*$_, 0 .. 100; my @id6; do_canvas4();

Using '&subname' is generally not what you want; use 'subname()' unless you really know why you're not. See perlsub for more on that.

— Ken


In reply to Re: Tkx scrolling by kcott
in thread Tkx scrolling by nitep70

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.