I'm trying to build a table using Tk::MListbox for it's sorting and column dragging capabilities, but cannot get it to scroll. I tried using the Scrolled() shortcut method first, but it died, so I resorted to the 'long way'. This is what my code looks like:
my $table = $MainFrame-> MListbox( -selectmode => 'single', -columns=>[ [-text=>'Date', -sortable=>1, + -width => 0], [-text=>'Time', -sortable=>1, + -width => 0], [-text=>'Name', -sortable=>1, + -width => 0], [-text=>'Address', -sortable=>1, + -width => 0], [-text=>'Phone', -sortable=>1, + -width => 0] ] )->pack(-fill=> 'both' +, -expand =>1, -side=>'left', -ipadx => 5);; while($result->fetch()){ ### Results from DB query $table->insert('end', [$Date, $Time, $Name, $Address, $Phone]); } my $scroll = $MainFrame->Scrollbar(-command => ['yview', $table]); table->configure(-yscrollcommand => ['set', $scroll]); $scroll->pack(-side => 'right', -fill => 'y');


When I run this, the table and the scrollbar loads but it won't scroll. Sorting and dragging are also broken.

Here is what is dumped to the console:

error:Not a CODE reference at C:/Perl/site/lib/Tk/MListbox.pm line 72 +3. Tk::Error: Not a CODE reference at C:/Perl/site/lib/Tk/MListbox.pm lin +e 723. Tk::Widget::Callback at C:/Perl/site/lib/Tk/Widget.pm line 1149 Tk::CListbox::yview at C:/Perl/site/lib/Tk/MListbox.pm line 66 Tk::Derived::Delegate at C:/Perl/site/lib/Tk/Derived.pm line 463 Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm line 322 Tk::MListbox::yscrollCallback at C:/Perl/site/lib/Tk/MListbox.pm line + 700 <Configure> (command bound to event)
When you attempt to scroll you get:
error:Not a CODE reference at C:/Perl/site/lib/Tk/MListbox.pm line 720 +. error:Not a CODE reference at C:/Perl/site/lib/Tk/MListbox.pm line 72 +0. Tk::Error: Not a CODE reference at C:/Perl/site/lib/Tk/MListbox.pm lin +e 720. Tk::Widget::Callback at C:/Perl/site/lib/Tk/Widget.pm line 1149 Tk::CListbox::yview at C:/Perl/site/lib/Tk/MListbox.pm line 66 Tk::Derived::Delegate at C:/Perl/site/lib/Tk/Derived.pm line 469 Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm line 322 Tk::MListbox::yview at C:/Perl/site/lib/Tk/MListbox.pm line 911 Tk::Scrollbar::ScrlByUnits at ..\blib\lib\Tk\Scrollbar.pm (autosplit +into ..\blib\lib\auto\Tk\Scrollbar\ScrlByUnits.al) line 336 Tk::Scrollbar::Select at ..\blib\lib\Tk\Scrollbar.pm (autosplit into +..\blib\lib\auto\Tk\Scrollbar\Select.al) line 201 Tk::Scrollbar::ButtonDown at ..\blib\lib\Tk\Scrollbar.pm (autosplit i +nto ..\blib\lib\auto\Tk\Scrollbar\ButtonDown.al) line 159 <Button-1> (command bound to event)
If you replace the MListbox with a normal listbox, it works just fine.

Is this a limitation with MListbox? As useful as this sort of widget would be, I can't imagine there isn't an easy way to do it.

In reply to scrolling MListbox in Perl/tk by vortmax

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.