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"; }

In reply to simultaneous selections in Tk by momo33

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.