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

I believe that I made some similar code work before, but that was at home on WinXP. Now this is on Windows 2000 and with Perl 5.8.4.

The problem is that when the Listbox lost focus, its selection is also lost. So if I have two Listboxes, I cannot make both of them have row selected.

I have tried different selectmode and exportselection, no use.

Here is a strip down version of the code:

use Net::Telnet; use Tk; use Tk::ROText; use XML::Simple; use Data::Dumper; use strict; use warnings; my $mw = MainWindow->new(); my $f = $mw->Frame(-border => 1)->pack(-side => "left", -fill => "both +"); my $envs_list; $envs_list = $f->Scrolled("Listbox", -scrollbars=>"e", -exportselectio +n => 1, -selectmode=>"extended")->pack(-fill => 'both'); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); my $list; $list = $f->Scrolled("Listbox", -scrollbars=>"e", -exportselection => +1, -selectmode=>"extended")->pack(-fill => 'both'); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); MainLoop;

20041118 Edit by castaway: Changed title from 'Have multiple Listboxes selected'

Replies are listed 'Best First'.
Re: Have multiple Tk::Listboxes selected
by zentara (Cardinal) on Nov 17, 2004 at 22:34 UTC
    You have the "exportselection" backwards. Try this:
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $f = $mw->Frame(-border => 1)->pack( -side => "left", -fill => "both"); my $envs_list; $envs_list = $f->Scrolled("Listbox", -scrollbars=>"e", -exportselection => 0, -selectmode=>"extended") ->pack(-fill => 'both'); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); my $list; $list = $f->Scrolled("Listbox", -scrollbars=>"e", -exportselection => 0, -selectmode=>"extended") ->pack(-fill => 'both'); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $list->insert("end", "abcd"); $mw->Button( -text => "Selections", -command => sub{ my $selected_env_list= $envs_list->get( $envs_list->curselection ); + my $selected_list = $list->get( $list->curselection ); print "selected-> $selected_env_list $selected_list\n"; } )->pack( -side => 'left' ); $mw->Button( -text => "Exit", -command => \&exit )->pack; MainLoop;

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

      You were right! Thanks, also to traveler.

Re: Have multiple Tk::Listboxes selected
by traveler (Parson) on Nov 17, 2004 at 22:32 UTC
    I have 5.8.4. The behavior you are seeing is the intended default. I set both exportselection values to 0 and it worked for me.

    --traveler

      "The behavior you are seeing is the intended default. "

      The following code proves what traveler said. I removed exportselection option, and print out its default value, it was 1:

      use Tk; use Tk::ROText; use XML::Simple; use Data::Dumper; use strict; use warnings; my $mw = MainWindow->new(); my $f = $mw->Frame(-border => 1)->pack(-side => "left", -fill => "both +"); my $envs_list; $envs_list = $f->Scrolled("Listbox", -scrollbars=>"e", -selectmode=>"e +xtended")->pack(-fill => 'both'); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); $envs_list->insert("end", "abcd"); print $envs_list->cget('-exportselection'); MainLoop;