Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl TK Scrollbar Pane : automatic scrolling

Status
Not open for further replies.

landraille

Programmer
Apr 18, 2011
2
FR
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.

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
 
Unfortunately, I'm not a user of Tk, so I don't know how to advise you.

However, I did streamline your code a little bit in a way that might help others assist you.

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..9,'a'..'i');

MainLoop;

sub LIST {
	my @list = @_;
	
	my $nb_line_list = scalar @list;
	my $list = $scroll_bar->Listbox(-height=> "$nb_line_list")->pack;
	my $button_OK = $scroll_bar->Button(-text=> 'OK')->pack;

	for (@list) {
		$list->insert('end', $_);
	}
	$list->selectionSet(0);

	$button_OK->configure(
		-command => sub { LIST(@list) },
	);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top