landraille
Programmer
Hi,
I'm just learning Perl/Tk and I have a problem with the scrollbar. Like this person ( I would like the scrollbar to scroll to the bottom everytime a listbox is inserted in my main window.
However, I use Scrolled ('Pane') and not Scrolled ('ROText'), so the "see ('end')" doesn't work.
I know that this script is useless and has no meaning (always the same list that appears, without treatment of the selected element, etc..) but I hope that it can help you to understand that i want.
Thanks
I'm just learning Perl/Tk and I have a problem with the scrollbar. Like this person ( I would like the scrollbar to scroll to the bottom everytime a listbox is inserted in my main window.
However, I use Scrolled ('Pane') and not Scrolled ('ROText'), so the "see ('end')" doesn't work.
I know that this script is useless and has no meaning (always the same list that appears, without treatment of the selected element, etc..) but I hope that it can help you to understand that i want.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Pane;
#### Mainwindow #########
my $mw = MainWindow->new();
$mw->minsize (300,350);
my $scroll_bar = $mw->Scrolled('Pane',
-scrollbars => 'e',
)->pack(-expand => 1, -fill => 'both');
&LIST('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i');
MainLoop;
sub LIST
{
my $nb_line_list=scalar(@_);
my $list = $scroll_bar->Listbox(-height=> "$nb_line_list")->pack;
my $button_OK = $scroll_bar->Button(-text=> 'OK')->pack;
my $i =0;
while (defined($_[$i]))
{
$list->insert('end',"$_[$i]");
$i++;
}
$list->selectionSet(0);
$button_OK->configure(
-command => sub {
my $ID=$list->curselection();
my $select=$list->get($ID);
&LIST('1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i');
}
);
}
Thanks