SBECK has asked for the wisdom of the Perl Monks concerning the following question:

***** NEVER MIND *****

While continuing to research the problem, I stumbled on this almost immediately after posting.

https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.perl.tk/ +-mMmqk43nhE

If you create the listboxes with the option -exportselection => 0 , the problems goes away. Just happened to get the right search terms in google this time.

****************************************

Environment: perl 5.16.0 and Tk 804.030

I've got a Tk app with 2 listboxes, and when I set the selection on one, it interferes with the selection on the other. A simple sample is:

use warnings 'all'; use strict; use Tk; our ($main_window,$main_frame,$list1,$list2); $main_window = MainWindow->new(); $main_frame = $main_window->Frame->pack(); $list1 = $main_frame->Listbox()->pack(); $list1->insert('end','list1'); $list2 = $main_frame->Listbox()->pack(); $list2->insert('end','list2'); $list2->selectionSet(0); print $list2->selectionIncludes(0),"\n"; $list1->selectionSet(0 ); print $list2->selectionIncludes(0),"\n"; MainLoop;

I would expect it to print out two '1' lines since I don't see how setting the selection on $list1 should alter the selection on $list2. Instead it prints out a 1 followed by a 0, so by setting the selection on $list2, the selection on $list1 was removed.

I haven't seen this mentioned in any of the Tk docs I've read, so it's maybe a bug, but I'd like to confirm that I'm not missing something.

Any suggestions?

Replies are listed 'Best First'.
Re: Tk problem: 2 listboxes interfering with each other (typo/name1/name1)
by Anonymous Monk on Feb 22, 2013 at 13:49 UTC

    Any suggestions?

    You call your vars $list1 and $list2, but you only interrogate $list2 (you only call $list2->selectionIncludes

    It would have been easier to notice if you had $leftList and $rightList or some such word-length non nummerical prefix/suffix