Would you believe that I wanted to give the OP some experience sorting thru lousy long variable names? :-)

To be honest, it was early, and I just pasted the first example I came across, but now that I look closer, it does have alot of fluff in it. :-)

But in my defense, I had a simple non-complicated example like yours, BUT, the OP claimed unfamiliarity with pTk, so I wanted an example that was very elementary, showing each step in excruciating newbie detail....... the adding to the listboxes, and how to get both selections with a button(or command). Also, your for() syntax is clever, but not standard, and I would hate to have a new user thinking that was a good template for setting up listboxes.

Here is how I would do a rewrite

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $f = $mw->Frame( -border => 1 )->pack( -side => "left", -fill => "b +oth" ); #just manipulate arrays to change lists my @list1 = ( 'a' .. 'z' ); my @list2 = ( 1 .. 100 ); my $list1 = $f->Scrolled( "Listbox", -listvariable => \@list1, -scrollbars => "osoe", -exportselection => 0, -selectmode => "extended" )->pack( -fill => 'both' ); my $list2 = $f->Scrolled( "Listbox", -listvariable => \@list2, -scrollbars => "osoe", -exportselection => 0, -selectmode => "extended" )->pack( -fill => 'both' ); $mw->Button( -text => "Selections", -command => sub { my $selected1 = $list1->get( $list1->curselection ); my $selected2 = $list2->get( $list2->curselection ); print "selected-> $selected1 $selected2\n"; } )->pack( -side => 'left' ); $mw->Button( -text => "Exit", -command => sub { exit } )->pack; MainLoop;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re^3: Perl/TK listbox question by zentara
in thread Perl/TK listbox question by tarlos25

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.