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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with pTk and passing listbox methods as args to function pls

Status
Not open for further replies.

greadey

Technical User
Oct 25, 2001
231
GB
Hi all here's a tricky one I think;

First a code example using a Tk::Listbox;

my @list = (qw/1 2 3 4 5/);

$mw = MainWindow;
$list1 = $mw->Listbox->pack;
$list2 = $mw->Listbox->pack;
$but = $mw->Button(-text => 'Add',
-command => [\&ADD, $list1->curselection])->pack;

MainLoop;

sub ADD {

(my $index) = @_;

$list2->insert('end', $index);

}

What happens is $index is undefined.
if you change ADD to be;

sub ADD {

$list2->insert('end' $list1->curselection);

}

it all works tickety boo. So can anyone tell me why when the curselection method returns a scalar, I can't pass it as an argument to a function?
 
oops sorry - forgot the line;

$list1->insert('end', @list) after the line;

$list1 = $mw->Listbox...........
 
REPLACE:
$but = $mw->Button(-text => 'Add',
-command => [\&ADD, $list1->curselection])->pack;

WITH:
$but = $mw->Button(-text => 'Add', -command => sub{&ADD($list1->get('active'));})->pack;

and it should work.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top