Hi fellows, This is my first time on PerlMonks and honestly speaking I am somewhat nervous as I do not consider myself to be a professional programmer, however, I and doing my best to learn the ropes. Maybe one day. In the meanwhile, I have started to develop a Perl Tk Gui that will ultimately output a Organisational Chart in Excel. I seem to be able to get the GUI to add numerous rows of listbox from which a user will be able to select values (to be retrieved from an Excel CSV). The only problem that I have now is to retrieve the values from all the input (i.e. all the entry and list boxes). I am stuck and would like to know how I could go about doing this. Any pointers would be greatly appreciated.
use Tk; require Tk::BrowseEntry; #use warnings; use strict; my ($entry,$f,$mw,$top,$entry2,$f1); $mw = MainWindow->new(-title => "Organizational Chart Generator"); $mw->geometry( "800x400" ); $f = $mw->Frame(-borderwidth => 2, -relief => 'groove') ->pack(-side => 'top', -fill => 'x'); $entry = $f->Label(-text=>"Division Title:")->pack(-side => "left", -anchor => "n", -fill => "x", -expand => "y"); $entry = $f->Entry( -textvariable => '', -width => 40); $entry->pack(-side => "left", -anchor => "n", -fill => "x", -expand => "y"); my $addbutton = $f->Button(-text => "Add Chart Blocks", -command => \&addwidget )->pack(-anchor => 's'); my $addbutton2 = $f->Button(-text => "Generate Chart", -command => \&genchart )->pack(-anchor => 's'); $mw->Button(-text=>'exit', -command=>sub{exit;})->pack(); MainLoop; sub addwidget { my @divisions = qw (AF AF CSPL CSPL CSO DGG DG FR FRAT OC OCX OCX + OC); my @unique; my %seen; @unique = grep { ! $seen{$_}++ } @divisions; my @s = sort {$a cmp $b} @unique; my $f1 = $f->Frame->pack(-side => 'top', -expand => 1, -fill =>'y', -before => $addbutton); # my $f2 = $f->Frame->pack(-side => 'top', -expand => 1, # -fill =>'y', -before => $addbutton2); $mw = $f1->Label(-text=>"Division Unit:")->pack( -side => "left", -anchor => "n", -fill => "x", -expand => "y"); $mw = $f1->Entry( -textvariable => '', -width => 40); $mw->pack(-side => "left"); $f1->ScrlListbox(-label => 'Right-Hand Area of Chart', -selectmode => 'multiple', -height => 5, -listvariable => \@divisions, -exportselection => 0) ->pack(-ipady => '5', -side=>'left'); $mw = $f1->Entry(-textvariable => '', -width => 40); $mw->pack(-side => "left",); $f1->ScrlListbox(-label => 'Middle Area of Chart', -selectmode => 'multiple', -height => 5, -listvariable => \@divisions, -exportselection => 0) ->pack(-ipady => '5', -side=>'left'); $mw = $f1->Entry(-textvariable => '', -width => 40); $mw->pack(-side => "left",); $f1->ScrlListbox(-label => 'Right-Hand Area of Chart', -selectmode => 'multiple', -height => 5, -listvariable => \@divisions, -exportselection => 0) ->pack(-ipady => '5', -side=>'left'); } sub genchart { #This does not work my @inds = $f1->curselection(); my @sels; foreach my $i ( @inds ){ print $f1->get( $i ), "\n"; } #I have tried this, and no luck. # print join ':', map { $_->Subwidget('entry')->get } @be; }
Debug error follows:
Tk::Error: Can't call method "curselection" on an undefined value at C +:\Users\Ettore Vecchione\Desktop\ORG CHART APP\chart.pl line 135. Tk callback for .frame.button1 Tk::__ANON__ at C:/Perl64/site/lib/Tk.pm line 251 Tk::Button::butUp at C:/Perl64/site/lib/Tk/Button.pm line 175 <ButtonRelease-1> (command bound to event)
I do not know how to pass the values from the gui to the subroutine I have named genchart(). Should I use a bind method via the Generate Chart submit button instead? I have tried to capture via the sub widget method, however, this does not work. I wonder if I should be building my widgets using the grid method as well.

In reply to 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.