If I understand your question, you are using the simplest, default configuration for your two listboxes, which means that when you select an item in one box, the current selection in the other box goes away; and you want to know which listbox has a currently selected item. Just check which box has a non-empty "curselection".
Here is a really simple-minded extension of the code you posted, which should demonstrate what you're looking for:
#!/usr/bin/perl
use strict;
use Tk;
my @list1 = qw/one two three four five six seven eight nine/;
my @list2 = qw/green blue red yellow orange black brown white purple/;
my $list_used;
my $mw = MainWindow->new;
my $lb1 = $mw->Scrolled('Listbox')->pack;
my $lb2 = $mw->Scrolled('Listbox')->pack;
my $b = $mw->Button(-text => "do it", -command => \&do_it)->pack;
$lb1->insert( 'end', @list1 );
$lb2->insert( 'end', @list2 );
MainLoop;
sub do_it
{
if ( $lb1->curselection ) {
print " got item from lb1: ",$lb1->get($lb1->curselection),$/;
}
elsif ( $lb2->curselection ) {
print " got item from lb2: ",$lb2->get($lb2->curselection),$/
+;
}
else {
print "Nothing was selected\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.