USCG360D has asked for the wisdom of the Perl Monks concerning the following question:

Hi everybody, I am programming GUI, which is a table, so that we can fill the table through the GUI and then save the values just filled in to some file, after click the "finish" button. The question is that how we can fill in the value and how we can extract values from the table. My code is like following, what should I change. Thank you very much!
#!/perl/bin/perl -w #use strict; use warnings; use Tkx; Tkx::package_require("Tktable"); my $mw = Tkx::widget->new("."); %hash = ( # data to display '1,0' => 'Vertical', '2,0' => 'Lng', '3,0' => 'Lateral', '0,1' => 'Expected shifts (A)', '0,2' => 'Shifts based on img alignment (B)', '0,3' => '|A-B|', ); my $t = $mw->new_table ( -rows => 4, -cols => 4, -cache => 1, -variable => \%hash, ); $t->g_pack(-fill => 'both', -expand => 1); $b=$mw->new_button (-text=>"Finish", -command=>sub {RecordData()}, ); $b->g_pack(); sub RecordData() { # save the data input in the table to a file }; Tkx::MainLoop();

Replies are listed 'Best First'.
Re: a perl tkx GUI
by Anonymous Monk on May 22, 2013 at 03:04 UTC

    Mwahahahaha

    #!/usr/bin/perl -- use strict; use warnings; $Tkx::TRACE = 64; use Tkx; Tkx::package_require("Tktable"); my $mw = Tkx::widget->new("."); my %hash = ( # data to display '1,0' => 'Vertical', '2,0' => 'Lng', '3,0' => 'Lateral', '0,1' => 'Expected shifts (A)', '0,2' => 'Shifts based on img alignment (B)', '0,3' => '|A-B|', ); my $t = $mw->new_table ( -rows => 4, -cols => 4, -cache => 1, -variable => \%hash, ); $t->g_pack(-fill => 'both', -expand => 1); $mw->new_button( -text => 'Populate', -command => sub { my( $r, $c ) = ( $t->cget('-rows') , $t->cget('-cols') ); for my $rr ( 0 .. $r ){ for my $cc ( 0 .. $c ){ $t->set("$rr,$cc", "yo $rr, $cc oy" ); } } return; }, )->g_pack; $b=$mw->new_button (-text=>"Finish", #~ -command=>sub {RecordData()}, -command=>sub { RecordData(); #~ $mw->destroy; # err #~ $mw->Tkx::destroy; #~ http://docs.activestate.com/activeperl/5.16/lib/Tkx.html #~ http://docs.activestate.com/activeperl/5.16/lib/Tcl/tkkit.html #~ http://docs.activestate.com/activetcl/8.5/tktable/tkTable.html #~ pathName get first ?last? #~ Returns the value of the cells specified by the table indices first + and (optionally) last in a list. use Data::Dump; dd[ $t->configure ]; dd[ Tkx::SplitList( $t->configure ) ]; dd[ $t->cget('-rows') , $t->cget('-cols') ]; #~ dd[ $t->cget ]; dd[ $t->get( qw/ topleft bottomright / ) ]; #~ my $cols = $t->cget('-cols'); for my $row ( 0 .. $t->cget('-rows') ){ #~ dd[ $t->get( "$row.0, $row.$cols" ) ]; #~ bad table index "0.0, 0.4": must be active, anchor, end, origin, to +pleft, bottomright, @x,y, or <row>,<col> #~ dd [ map { $t->get( "$row,$_" ) } $t->cget('-cols') ]; dd [ map { $t->get( "$row,$_" ) } 0 .. $t->cget('-cols') +]; } $mw->g_destroy; }, ); $b->g_pack(); sub RecordData() { # save the data input in the table to a file }; Tkx::MainLoop();
      Thank you so much for the reply. as a new user of perl, I am trying to understand the program you wrote. I guess following code is to populate the value filled in from GUI into the table: $mw->new_button( -text => 'Populate', -command => sub { my( $r, $c ) = ( $t->cget('-rows') , $t->cget('-cols') ); for my $rr ( 0 .. $r ){ for my $cc ( 0 .. $c ){ $t->set("$rr,$cc", "yo $rr, $cc oy" ); } } return; }, )->g_pack; Can you give some comments on the code or give me some website that talk about this in detail? Thank you so much!

        Can you give some comments on the code or give me some website that talk about this in detail? Thank you so much!

        About what exactly , can you be specific?

        I linked the tkx/tk docs and tutorials (which link other tutorials) ... Have you read perlintro?