Change in Scrolled Listbox behaviour?
Colin Tuckley <[email protected]> Wed, 21 Mar 2007 12:21:37 +0000
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
Can someone please confirm that the behaviour of the curselection
function/value of scrolled listbox has changed. Either as the result of a
Perl or a Perl/Tk change.
System is Debian Etch/Testing.
I had the following code:
$fontlistbox = $flb->Scrolled("Listbox", -scrollbars => "se", -selectmode
=> "single")->pack();
foreach $i ( @fontnames) {
$fontlistbox->insert('end', $i);
}
$fontlistbox->bind('<Button-1>',
sub{$fontfamily[$label_id][$which_field] =
$fontnames[$fontlistbox->curselection];
modify_fonts() }
);
This worked until recently but has started generating the following error:
"Use of reference "ARRAY(0x8858814)" as array index" for the line where
curselection is referenced.
Mastering Perl/Tk says that curselection returns a list of the selected
items. If this was the case then I don't see how it ever worked (which it
did) unless something was cunningly knowing that because "single" is set we
only ever get one selected item and so was just returning the index value
instead of a list.
I've changed the code to:
$fontlistbox->bind('<Button-1>',
sub{my @sel = $fontlistbox->curselection;
$fontfamily[$label_id][$which_field] = $fontnames[$sel[0]];
modify_fonts() }
);
Which works as expected. Is there a more elegant way of writing that? The
error message seems to imply that an array reference is being returned, is
this equivalent to a list?
regards,
Colin
--
Colin Tuckley | [email protected] | PGP/GnuPG Key Id
+44(0)1903 236872 | +44(0)7799 143369 | 0x1B3045CE
"Heisenberg may have slept here"
--++**==--++**==--++**==--++**==--++**==--++**==--++**==
ptk mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/ptk