Hello

Here is a section of my perl program that uses the Tk module. I have two listboxes in the same window
sub meter{ my $metw = MainWindow-new; $metw->geometry("500x500"); $metw->title("Meter work details"); $metw->configure(-background=>'purple'); my $frame8=$metw->Frame(-relief=>'groove', -borderwidth=>3, -backgrou +nd=>'blue',)->pack(-side=>'top', -pady=>15, -padx=>15); my $label8=$frame8->Label(-text=>'Enter consumer name',-background=>'b +lue', -foreground=>'white',)->pack(-side=>'left'); $entry8=$frame8->Entry(-width=>30,-background=>'white')->pack(-side=>' +left', -pady=>3); ($label10 = $metw->Label(-text=>'Double click on subdivision name',-ba +ckground=>'blue', -foreground=>'white'))->pack(-side=>'top',-pady=>2) +; $sd_list = $metw->Listbox(-exportselection => 0)->pack; $sd_list->insert('end', "loc1","loc2","loc3","loc4","loc5","loc6", "lo +c7", "loc8", "loc9","loc10","loc11","loc12","loc13"); $sd_list->bind('<Double-1>', \&meter_subdivision); sub meter_subdivision { my $sd = $sd_list->get('active'); return $sd; } ($space16 = $metw->Label(-text=>' ',-background=>'purple') +)->pack; ($space17 = $metw->Label(-text=>' ',-background=>'purple') +)->pack; ($labeln = $metw->Label(-text=>'Double click on appropriate option',-b +ackground=>'blue', -foreground=>'white'))->pack(-side=>'top',-pady=>2 +); $nr_list = $metw->Listbox(-listvariable => $_, -exportselection => 0)- +>pack; $nr_list->insert('end',"New service","Replacement"); $nr_list->bind('<Double-1>',\&type_meter_work); sub type_meter_work { my $tmw = $nrd_list->get('active'); return $tmw; } ($space8 = $sw->Label(-text=>' ',-background=>'purple'))-> +pack; ($space9 = $sw->Label(-text=>' ',-background=>'purple'))-> +pack; my $label7=$metw->Label(-text=>'Enter phase : single/three',-backgroun +d=>'blue', -foreground=>'white',)->pack(-side=>'top'); $entry7=$metw->Entry(-width=>30,-background=>'white')->pack(-side=>'to +p', -pady=>3); $space10 = $sw->Label(-text=>' ',-background=>'purple'))-> +pack; $space11 = $sw->Label(-text=>' ',-background=>'purple'))-> +pack; $metw->Button(-text=>'Print receipt',-background=>'blue',-command=>\&m +eter_fwrite_print)->pack(-side=>'top',-pady=>2); }
When i try to print the selected items in both the lists in another subroutine, i get the following error:
Tk::Error: Can't call method "get" on an undefined value at C:\Perl\pr +ograms\cash_counter.pl line 167. <Double-Button-1> (command bound to event)
If i have only one listbox in the window the value of the selected item is printed just fine.

In fact i would like to replace the"Enter phase" label with a list box too to reduce typing for the user.So three listboxes in one window.

Also how to use a single click instead of double click for selection.Will this cause any problems?

Please help.

In reply to Perl/Tk listbox question by perl_seeker

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.