滚动条在填充了长列表框的滚动窗格中不起作用
我有一个滚动窗格,然后填充一系列长列表框以制作图表。底部的滚动条工作正常,但右侧的滚动条表明查看区域之外没有任何内容,但是当我调整窗口大小时,我看到许多隐藏的行。我尝试过以各种顺序打包框架和列表框(打包列表框然后填充它们,填充列表框以便它们已满然后打包它们等等),但无论我做什么,右侧的滚动条都不会似乎不明白列表框比窗格高。
实际的程序有点复杂,但这里有一个简化的示例,通过限制几何图形来显示行为。在我的实际情况中,我永远不知道图形的宽度或高度,但如果我不指定几何形状,窗口就会非常小。
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->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
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->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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我明白了。问题在于垂直滚动条被键入到列表框的高度。默认值为 10,完全在我在几何设置中设置的高度之内。当我在填充所有设置真实高度的列表框后添加一行时,滚动条开始工作。
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.