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

Hello monks,

I'm writing an analysis program where I need to make a series of selections before the proces can start. For that I have several listboxes. Unfortunately, if I make a selection in the second listbox, the selection in this first one disappears. What do I do incorrectly?

The code attaches is not the simplest possible, but is a minimal version of my problem-code. It has two listboxes, and I want the selection in the top one to stay selected when I make a selection in the bottom listbox.

Any suggestions? Thank you!
#!/usr/bin/perl use strict; use Tk; my $mw = MainWindow->new; my $gui_period = $mw->Scrolled( qw/Listbox -height 5 -width 20 -background white -selectforeground red/ ); my $gui_report = $mw->Scrolled( qw/Listbox -height 5 -width 20 -background white -selectforeground blue/ ); $gui_period->grid( -row => 0, -column => 0, -rowspan => 1, -sticky => +'nsew' ); $gui_report->grid( -row => 1, -column => 0, -rowspan => 1, -sticky => +'nsew' ); $gui_period->bind( '<ButtonRelease-1>' => \&show_period ); $gui_report->bind( '<ButtonRelease-1>' => \&show_report ); my ($item); my @periodlist = qw/one two three four/; foreach $item (@periodlist) { $gui_period->insert( 'end', $item ); } my @reportlist = qw/first second third fourth/; foreach $item (@reportlist) { $gui_report->insert( 'end', $item ); } MainLoop; sub show_period { my @index = $gui_period->curselection(); my $index = $index[0]; $gui_period->selectionSet($index); print "period: $index $periodlist[$index]\n"; } sub show_report { my @index = $gui_report->curselection(); my $index = $index[0]; $gui_report->selectionSet($index); print "report: $index $reportlist[$index]\n"; }

Replies are listed 'Best First'.
Re: simultaneous selections in Tk
by zentara (Cardinal) on Nov 02, 2008 at 16:40 UTC
    Add the -exportselection => 0 option to all listboxes.
    #need exportselection=>0 for using multiple selection boxes my $lb0 = $mw->Listbox(-selectmode => 'extended', -exportselection=> 0 )->pack;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      This seems to work. Not the first thing I thought of.
      Thank you.
        Not the first thing I thought of

        Heh, heh....don't worry, I think every Tk user has asked that question the first time they use Listboxes..... I did too. :-) It is listed as an option in the perldoc, but dosn't say what it's for.


        I'm not really a human, but I play one on earth Remember How Lucky You Are