Thanks for all the input. I have now gone about creating another version implementing everyone's suggestions, however, there remains the issue of capturing values from additional widgets added dynamically. I cannot foresee how many widgets (i.e. listbox or entry ) will be added by the user. And so, I would really appreciate some additional pointers regarding how to implement this kind of coding. I cannot find any suggestions based on Learning Perl/Tk nor Mastering Perl/Tk. Here is the new, yet, still defective code. I have implemented the grid method to dynamically generate the widgets. As you can see, I can retrieve values only for one row of list and entry boxes based on static assignment but nothing beyond this. Moreover, the entry boxes overlap the listbox widgets.
use strict; use warnings; use Tk; my $lb=1; my $textboxrow = 2; my $textboxrowMid = 2; my $fieldbuttonrow = 3; my $textbox = 0; my $textbox2 = 1; my $textboxMid = 0; my $textboxMid2 = 1; my ($be,$be1, @be,@me,$label,$label2, $ent,$ent2,$entry_1,$entry_2); my $mw = tkinit; $mw -> geometry("400x300"); my $button = $mw->Button(-text => 'Add Field', -command => \&addtext +box); my $button2 = $mw->Button(-text => 'Print texts',-command => \&printte +xts); addtextbox(); MainLoop(); sub addtextbox{ my @divisions = qw (AF CSPL CSO DGG DG FR FRAT OCX OC); $label=$mw->Label(-text=>"Division Unit:")->pack(); $ent = $mw -> Entry(-textvariable => \$entry_1,) -> pack(); $be = $mw->Listbox(-bg => 'white', -selectmode => 'extended', -exportselection=> 0 )->pack; $be->insert( 'end', @divisions ); $label2=$mw->Label(-text=>"Division Unit:")->pack(); $ent2 = $mw -> Entry(-textvariable => \$entry_2,) -> pack(); $be1 = $mw->Listbox(-bg => 'white', -selectmode => 'extended', -exportselection=> 0 )->pack; $be1->insert( 'end', @divisions ); $label ->grid(-row=>$textbox++, -column=>1); $ent ->grid(-row=>$textbox2++, -column=>1); $be ->grid(-row=>$textboxrow++, -column=>1); $label2 ->grid(-row=>$textboxMid++, -column=>2); $ent2 ->grid(-row=>$textboxMid2++, -column=>2); $be1 ->grid(-row=>$textboxrowMid++, -column=>2); $button ->grid(-row=>$fieldbuttonrow++,-column=>1,-columnspan=>2); $button2->grid(-row=>$fieldbuttonrow ,-column=>1,-columnspan=>2); } sub printtexts { my @entry_1 = $ent->get(); my @entry_2 = $ent2->get(); my @values = $be->curselection(); my @values2 = $be1->curselection(); foreach (@entry_1) { print $_,"\n" } foreach my $v (@values) { print $be->get($v),"\n"; } foreach (@entry_2) { print $_,"\n" } foreach my $vv (@values2) { print $be1->get($vv),"\n"; } }
Many thanks again.

In reply to Re^2: TK Gui Help by GuiPerl
in thread TK Gui Help by GuiPerl

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.