On Tue, Mar 31, 2009 at 13:16, Thomas H. George <[email protected]> wrote:
> On Tue, Mar 31, 2009 at 12:17:24PM -0400, Chas. Owens wrote:
>> On Tue, Mar 31, 2009 at 11:27, Thomas H. George <[email protected]> wrote:
>> > I have tried a dozen different ways but can't retrieve an item from a
>> > list box. With a cursor
> left clicked
>> > on the item it is highlighted (= active?) but
>> > code such as
>> >
>> > $selected = $lbox -> get('active');
>> > print $selected;
>> >
>> > prints the last item in the list.
>> >
>> > What am I doing wrong?
>>
>> Well, the first thing you are doing wrong is not telling us what
>> module you are using. Without that we cannot begin to help you.
>>
> use Tk;
> ...
> $tl1 = $mw -> Toplevel(-height => 500,
> -width => 300);
> $lbox = $tl1 -> Listbox -> pack(-fill => 'both');
> $lbox -> insert('end', @files);
>
> Tom
Most likely your problem is that you are not waiting for the user to
choose an item from the list. Here is a script that displays a list
and prints the current item every time the user clicks the "press me"
button.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new;
my $lbox = $mw->Listbox->pack(-fill => 'both');
my $button = $mw->Button(
-text => "press me",
-command => sub {
print $lbox->get("active"), "\n";
}
)->pack;
$lbox->insert('end', qw/foo bar baz/);
MainLoop;
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/