Le code suivant produit à peu près ce que je veux, mais le volet déroulant sur la gauche ne défile pas. J'utilise ActivePerl 5.8.9 construire 825:Pourquoi mon Perl/Tk Scrolled ne défile-t-il pas?
Le code est:
use Tk;
use Tk::Pane;
use Tk::LabFrame;
# create the application window
my $MW = MainWindow->new (-background => "GREY");
# set the x/y size for the window
$MW->geometry("800x600");
# add a window title
$MW->title("Monitor Boxes");
# Disallow window resizing
$MW->resizable(0,0);
# create a labelled frame on the window to house the list of buttons to be pressed
$boxListFrame = &create_framed_section("List Of Boxes",
"acrosstop",
5,
5,
170,
565,
"BLUE",
"GREY");
# create a labelled frame on the window to house the information to be displayed
# when a particular button is pressed
$statusOfBoxFrame = &create_framed_section("Status",
"acrosstop",
185,
5,
600,
565,
"BLUE",
"GREY");
# create a scrollable pane in the left hand pane so that if more buttons than
# is able to be displayed are put onto the application the scroll bar will allow
# the ones not displayed to be access
my $pane = $MW->Scrolled( 'Pane',
-scrollbars => 'e',
-width => 140,
-height => 555,
-background => "GREY")->place(-x=>15,-y=>25);
# setup the array of buttons
@boxes = ("BUTTON1", "BUTTON2", "BUTTON3", "BUTTON4", "BUTTON5", "BUTTON6", "BUTTON7", "BUTTON8", "BUTTON9", "BUTTON10", "BUTTON11", "BUTTON12", "BUTTON13", "BUTTON14", "BUTTON15", "BUTTON16");
# put the buttons onto the scrollable pane in the frame on the window (LOL)
DisplayCheckButtons($pane, @boxes);
# wait until the user exits the app
MainLoop;
# exit the app
exit 0;
sub DisplayCheckButtons
{
my ($parent, @names) = @_;
$Frame->destroy if $Frame;
$Frame = $parent->Frame( -width => 160,
-height => 555,
-background => "GREY")->place(-x=>15,-y=>15);
$xpos = 5;
$ypos = 5;
foreach $box (@names)
{
$buttons->{$box} = $Frame->Button(-text => $box)->place(-x=>$xpos,-y=>$ypos);
$ypos = $ypos + 40;
}
}
sub create_framed_section
{
# get the parameters
my($label, $labelside, $posX, $posY, $width, $height, $fontColour, $backgroundColour) = @_;
# create the item in the desired position with supplied information
$frame = $MW->LabFrame(-label => $label,
-labelside => $labelside,
-width => $width,
-height => $height,
-foreground => $fontColour,
-background => $backgroundColour,
)->place(-x=>$posX,-y=>$posY);
return $frame;
}
J'espère que quelqu'un peut signaler la chose mineure que j'ai manqué de cette fin et ma frustration.
Glen, lorsque vous utilisez strict, vous devez déclarer vos variables avant de les utiliser. mon $ foo = 'bar'; Ou dans votre exemple ci-dessous, mes boutons $; $ boutons -> {$ box} = $ parent-> Bouton (-text => $ box) -> pack (-pady => 10); – daotoad