Yes, you don't explain exactly what your problem is, in terms of what you desire. Also, you don't give a working script to demonstrate your problem. From guessing at what you probably mean......

You can't use focusCurrent(or whatever ) because you change your focus when you click the do_it button. So you have 2 choices, you can use an alternate method to launch the sub, as I show with a right-mouse click. It is usually done this way. Listbox has default bindings for the left-click, so I used the right. Also you want to check out how the -exportselection works, when you have a couple of listboxes.

Now if you want to keep the do_it button, you will have to save which listbox was last clicked in a variable.

#!/usr/bin/perl use warnings; use strict; use Tk; my $lastactive = ''; my $mw = MainWindow->new; my $lb1 = $mw->Scrolled('Listbox', -exportselection => 0, )->pack; my $lb2 = $mw->Scrolled('Listbox', -exportselection => 0, )->pack; my $b = $mw->Button(-text=>"doit", -command=>sub{&do_it1})->pack; for(0..10){ $lb1->insert($_,$_); $lb2->insert($_,$_); } $lb1->bind( '<ButtonPress-1>', sub{$lastactive = 1} ); $lb2->bind( '<ButtonPress-1>', sub{$lastactive = 2} ); $lb1->bind( '<ButtonPress-3>', [\&do_it, 1 ] ); $lb2->bind( '<ButtonPress-3>', [\&do_it, 2 ] ); MainLoop; ################################################################ sub do_it { my( $object, $selbox ) = @_; my $i1 = $lb1->index('active'); my $i2 = $lb2->index('active'); print "selbox->$selbox lastactive->$lastactive $i1 $i2 \n"; } ################################################################ sub do_it1 { my $i1 = $lb1->index('active'); my $i2 = $lb2->index('active'); print "lastactive->$lastactive $i1 $i2 \n"; }

I'm not really a human, but I play one on earth. flash japh

In reply to Re: selection problem with two Tk listboxes by zentara
in thread selection problem with two Tk listboxes by fcvw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.