How about creating a scrolled listbox rather than separate scrollbar and listbox.
my $Scrolled_Search_Listbox = $mw->Scrolled(
q{Listbox},
-background => "white",
...
);
The following code is from an application with scrolling listboxes that were simple to implement.
I hope this is helpful. Cheers,
JohnGG | [reply] [d/l] [select] |
When I use Scrolled It doesn't want to updates the scroll when I load a lot of
data into the listbox.
| [reply] |
I've knocked up this little app. which inserts ten items into the listbox every time you hit the <Insert> button. It seems to update the scroll bar ok on my system, Sun Ultra 30, Solaris 9, perl 5.8.4, Tk-804.027.
use strict;
use warnings;
use Tk;
my $rcGetTen = do
{
my $count = 0;
sub
{
my @arr;
push @arr, q{Item } . ++ $count
for 1 .. 10;
return @arr;
};
};
my $bgColour = q{LightSteelBlue3};
my %labelColours =
(
-foreground => q{NavyBlue},
-background => q{LemonChiffon}
);
my %buttonColours =
(
-background => q{grey35},
-foreground => q{yellow2},
-activebackground => q{grey45},
-activeforeground => q{yellow},
-disabledforeground => q{grey55}
);
my %commonListboxOpts =
(
-setgrid => 1,
-scrollbars => q{e},
-selectmode => q{single},
-selectforeground => q{grey35},
-selectbackground => q{AntiqueWhite},
-exportselection => 0
);
my $mainWin = MainWindow->new(
-background => $bgColour,
);
$mainWin->title(q{scrollListbox});
my $listboxFrame = $mainWin->Frame(
-relief => q{flat},
-background => $bgColour,
-borderwidth => 2,
);
$listboxFrame->pack(
-side => q{top},
);
my $listbox = $listboxFrame->Scrolled(
q{Listbox},
%commonListboxOpts,
-width => 15,
-height => 6,
-setgrid => 1,
);
$listbox->pack(
-padx => 5,
-pady => 5,
-fill => q{y},
-expand => 1,
-anchor => q{n},
);
my $controlButtonFrame = $mainWin->Frame(
-relief => q{flat},
-background => $bgColour,
-borderwidth => 2,
);
$controlButtonFrame->pack(
-side => q{top},
);
my $quitButton = $controlButtonFrame->Button(
%buttonColours,
-width => 6,
-text => q{Quit},
-command => sub {exit;},
);
$quitButton->pack(
-side => q{right},
-padx => 5,
-pady => 5,
);
my $insertButton = $controlButtonFrame->Button(
%buttonColours,
-width => 6,
-text => q{Insert},
-command => sub { $listbox->insert( q{end}, $rcGetTen->() ) },
);
$insertButton->pack(
-side => q{right},
-padx => 5,
-pady => 5,
);
MainLoop();
I hope this is of interest. Cheers, JohnGG | [reply] [d/l] |
Well johngg is right to point you to the scrolled widget. However, if you really need to make your own scrollbar ( there are certain times you may need to do it), it is easier with pack than place. With pack you tell the scrollbar to fill in it's direction, like
$yscroll->pack( -side => 'left', -fill => 'y' );
$xscroll->pack( -side => 'bottom', -fill => 'x' );
I don't see 'fill' as an option to Tk::place, but if you read perldoc Tk::place, there are some options you can play with to try and make it the same size as the listbox, I would try the -relheight and -relwidth options. But pack is so much easier to use than place, so unless you need it for some reason, switch to pack, or use the Scrolled('Listbox'...)
| [reply] [d/l] |
You got me thinking when you said look into tk::place. I started reading
and found that you can change the height and width of the wig with place
Thank you for the reply
*** Problem Solved ***
For anyone who reads this later on all I did was this:
$Search_Listbox_Scrollbar->place(-x => 295, -y => 150, -height => 102)
+;
| [reply] [d/l] |