in reply to Tk::Listbox and Selection unexpected changes

#!/usr/bin/perl # https://perlmonks.org/?node_id=1226249 use strict; use warnings; use Tk; use Tk::ROText; my $message = ''; my $lb1pick = ''; my $lb2pick = ''; my $mw = MainWindow->new; my $label = $mw->Label( -textvariable => \$message, )->pack(); my $lb1 = $mw->Listbox( -exportselection => 0, )->pack(-side => 'left'); my $lb2 = $mw->Listbox( -exportselection => 0, )->pack(-side => 'left'); $lb1->insert(end => qw( one two three four five ) ); $lb2->insert(end => qw( six seven eight nine ten ) ); $lb1->bind('<ButtonRelease-1>' => sub { $lb1pick = $lb1->get('active'); $message = $lb1pick . ' ' . $lb2pick; }); $lb2->bind('<ButtonRelease-1>' => sub { $lb2pick = $lb2->get('active'); $message = $lb1pick . ' ' . $lb2pick; }); MainLoop;

Replies are listed 'Best First'.
Re^2: Tk::Listbox and Selection unexpected changes
by WayneRas (Acolyte) on Nov 24, 2018 at 05:54 UTC

    Thank you for your time and code. The penny dropped (which I quickly picked up to add to my therapist fund) when I saw the comment re exportselection.

    "Every man is a damn fool for at least five minutes a day. Wisdom comes in not exceeding that limit." - Elbert Hubbard
    I have exceeded my limit for the day! And in the interest of political correctness I was going to replace 'man' in the quote by entity but that would imply a woman (or alien for that matter in deference to the entity having the human experience) can be foolish and as a married man it would be foolish of me to imply that, as for aliens (assuming they have a choice) well they are just foolish for being here.