If Cristoforo's advice did not straighten out your problem, could you please rewrite your code with the mysql sample data hard coded in, so we can actually run it? I think you will see what is the problem. Here I just hard-coded @names and it works. I think you need to double check the output of @names from the db.
#!/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 @name = ([1, 'a'] , [2, 'b'] , [3, 'c'], [4 ,'d'] , [5, 'e'], [6, 'f'], [7, 'g'], [8, 'h'], [9, 'i'], ['a', 'j'], ['b +', 'k'] ); 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]->[0],-width => 8, -reli +ef =>'raised'); my $tmp_label1 = $table->Label(-text => $name[$i]->[1],-width => 8, -r +elief =>'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; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Fetch data from DB and put in to Table Tk by zentara
in thread Fetch data from DB and put in to Table Tk by gocpon

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.