CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
getting the text that's in a table

 



SamS
New User

Jun 27, 2011, 7:48 PM

Post #1 of 3 (819 views)
getting the text that's in a table Can't Post

I have a 2x8 table of lat/long that I can "put" text into the cells.
However, then I try to "get" the text, it doesn't show me the text.

Running the code gives:
The stuff that is in box (2,2) is Tk::LabEntry=HASH(0x8a74ff0)

But what I want it to print is:
The stuff that is in box (2,2) is SOME TEXT.


Code
#!/usr/bin/perl 
#
# wid2.pl
#

$|=1;

use Tk;

require Tk::LabFrame;
require Tk::LabEntry;
require Tk::Table;

my $mw = MainWindow->new;
$mw->geometry("+400+400");
my $LaLo = $mw->LabFrame(-label => "LaLo", -labelside => "acrosstop");
$LaLo->form(-top => '%0', -left => '0', -bottom => '%100');

my $table_frame = $LaLo->Frame()->pack();
my $table = $table_frame->Table(-columns => 2,
-rows => 10,
-fixedrows => 1,
-scrollbars => 'oe',
-relief => 'raised');

my $tmp_label = $table->Label(-text => "LAT" , -width => 8, -relief =>'raised');
$table->put(0, 1, $tmp_label);

my $tmp_label = $table->Label(-text => "LONG" , -width => 8, -relief =>'raised');
$table->put(0, 2, $tmp_label);


#generate the 2x8 table and put blank space in each one
foreach my $row (1 .. 8)
{
foreach my $col (1 .. 2)
{
$tmp_label = $table->LabEntry(-text => "",
-background => 'white',
-relief => "groove");
$table->put($row, $col, $tmp_label);
}
}

# Now put a value in one of them
$tmp_label=$table->LabEntry(-text=>"SOME TEXT");
$table->put(2,2,$tmp_label);

##########################################################################
# This is the part that doesn't work right
$THE_STUFF_THAT_IS_IN_BOX_2_2=$table->get(2,2);
print "The stuff that is in box (2,2) is $THE_STUFF_THAT_IS_IN_BOX_2_2\n";
##########################################################################


$table->pack();

MainLoop;



BillKSmith
Veteran

Jun 28, 2011, 4:10 AM

Post #2 of 3 (812 views)
Re: [SamS] getting the text that's in a table [In reply to] Can't Post

The scalar $THE_STUFF_THAT_IS_IN_BOX_2_2 contains a reference to a LabEntry object which contains the text. It is not a text string that you can print. There probably is a method to extract the string, but I do not know it.
Good Luck,
Bill


SamS
New User

Jun 29, 2011, 1:57 AM

Post #3 of 3 (797 views)
Re: [BillKSmith] getting the text that's in a table [In reply to] Can't Post

It turns out I needed an extra "->get()" at the end. Now it works!


Code
$THE_STUFF_THAT_IS_IN_BOX_2_2=$table->get(2,2)->get();


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives