gocpon has asked for the wisdom of the Perl Monks concerning the following question:
Dear All, I am trying to fetch data from two columns of the table of MYSQL and put those data into the table's(Tk).That Table(Tk)contains two labels, I want to column1's data to one label and column2's data to another label, but it is not happening. I have pasted my code here.Kindly help me.
#!/usr/bin/perl use Tk; use Tk::Entry; use Tk::Table; use Tk::LabFrame; use warnings; use strict; use DBI; my $v="0.00"; my $mw = MainWindow->new; $mw->geometry("250x400"); #$mw->resizable(0,0); $mw->title("Table Example"); my $db=DBI->connect('dbi:mysql:Payroll','root','gocpon') or die(); my $sh2=$db->prepare("select code,name from level "); $sh2->execute() or die(); my @name=$sh2->fetchrow_array; my @top2=qw/No Name Amount/; my $table_frame = $mw->LabFrame()->pack(-expand=>1, -fill=>'both'); my $table = $table_frame->Table(-columns => 10, -rows => 6,-fixedrows +=> 1, -scrollbars => 'oe',-relief => 'raised',-background=>'white'); my $j=0; my $i=0; my @ents; foreach my $j(1..11) { my $tmp_label=$table->Label(-text => $name[$i],-width => 8, -relief => +'raised'); my $tmp_label1 = $table->Label(-text => $name[$i],-width => 8, -relief + =>'raised'); my $tmp_label2= $table->Entry( -width => 8, -relief =>'raised',-bg => +'white',-validate=>'key'); $table->put($j,1,$tmp_label); $table->put($j,2,$tmp_label1); $table->put($j,3,$tmp_label2); push @ents, $tmp_label2; $i++; } $table->pack( -expand=>1 , -fill=>'both'); my $button_frame = $mw->Frame( -borderwidth => 4 )->pack(); $button_frame->Button(-text => "Exit", -command => sub {exit})->pack() +; &defineOrder( @ents ); MainLoop; sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind( '<Key-Return>', [\&focus, $_[$i+1]]); $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[ $#_ ]->bind('<Key-Return>', [\&focus, $_[0]]); $_[ $#_ ]->bind('<Tab>', [\&focus, $_[0]]); $_[0]->focus; } sub focus { my ($tk, $self) = @_; $self->focus; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fetch data from DB and put in to Table Tk
by zentara (Cardinal) on Jul 07, 2012 at 21:10 UTC | |
|
Re: Fetch data from DB and put in to Table Tk
by Cristoforo (Curate) on Jul 07, 2012 at 20:40 UTC | |
by gocpon (Novice) on Jul 08, 2012 at 08:15 UTC | |
by zentara (Cardinal) on Jul 08, 2012 at 11:22 UTC | |
by Cristoforo (Curate) on Jul 08, 2012 at 15:20 UTC | |
by Anonymous Monk on Jul 09, 2012 at 02:26 UTC | |
by Cristoforo (Curate) on Jul 09, 2012 at 13:19 UTC |