Scrollbar not working in Scrolled Pane populated with long listboxes
I have a Scrolled Pane which is then populated with a series of long listboxes to make a chart. The scrollbar on the bottom works perfectly, but the scrollbar on the right hand side indicates that there is nothing outside of the viewed region, but when I resize the window, I see many lines that were hidden. I've tried packing the frames and listboxes in all sorts of orders (packing the listboxes and then populating them, populating the listboxes so they are full and then packing them, etc) but no matter what I do, the scrollbar on the right doesn't seem to comprehend that the listboxes are taller than the Pane.
The actual program is a little more complex but here is a simplified example that shows the behavior by limiting the geometry. In my real case, I never know how wide or tall the graph will be but if I don't specify something for the geometry, the window is very small.
use strict;
use Tk;
require Tk::Pane;
my $mw = MainWindow->new;
my $graph_button = $mw->Button(-text => 'Make Graph',-command => sub {&make_graph} )->pack();
MainLoop;
exit;
sub make_graph {
my $summary_tl = $mw->Toplevel( -title => "My graph" );
$summary_tl->geometry("500x200");
my $summary_frame = $summary_tl->Scrolled ( "Pane",
-scrollbars => "se",
-sticky => 'nesw',
)->pack(-fill=>'both',-expand=>1);
# First column holds the names
my $name_frame = $summary_frame->Frame()->pack(-side=>'left',-fill=>'both',-expand=>1);
my $name_lb = $name_frame-&开发者_如何学Cgt;Listbox (-width=>0,-relief=>'flat',-borderwidth=>0)->pack(-side=>'top',-fill=>'both',-expand=>1);
$name_lb->insert('end',"Names");
# Second column shows the overall status
my $overall_frame = $summary_frame->Frame()->pack(-side=>'left',-fill=>'both',-expand=>1,);
my $overall_lb = $overall_frame->Listbox (-width=>0,-relief=>'flat',-borderwidth=>0)->pack(-side=>'top',-fill=>'both',-expand=>1);
$overall_lb->insert('end',"Overall Status");
# The next remaining columns are one per check of the current checklist, with the check number being the header.
my %stat_frame = ();
my %stat_lb = ();
foreach my $check_num (qw /1 2 3 4 5 6 7 8 9 10/) {
$stat_frame{$check_num} = $summary_frame->Frame()->pack(-side=>'left',-fill=>'both',-expand=>1);
$stat_lb{$check_num} = $stat_frame{$check_num}->Listbox(-width=>0,-relief=>'flat',-borderwidth=>0,) -> pack(-side=>'top',-fill=>'both',-expand=>1);
$stat_lb{$check_num}->insert('end',"Check $check_num");
}
# Now go through and add each row
foreach my $name (qw /a b c d e f g h i j k l m n o p q r s t u v w x y z/) {
$name_lb->insert('end',$name);
$overall_lb->insert('end',"pass");
foreach my $check_num (qw /1 2 3 4 5 6 7 8 9 10/) {
$stat_lb{$check_num} -> insert('end',"Status");
}
}
} # end make_graph subroutine
OK, I figured this out. The issue was that the vertical scrollbar was keyed into the height of the listboxes. The default there is 10 which was well within the height that I set in the geometry setting. When I added a line after populating all the listboxes that set the true height, the scrollbar started working.
精彩评论