Hi,
Thanks for your reply, I changed my code according to you, now my code is running but output is not correct I am getting 'q' for all label in first row of table (TK) and '1' for all label in the second row of the same table (TK). That MySQL table contains data like
Code Name
001 Level1
002 Level2
003 Level3
004 Level4
So I am expecting that first column(code) data of the MySql table should be present in to the first row labels of the Table(Tk) and the same time the second column(Name) data of the MySql table should be present in to the second row labels of the Table(Tk)for your reference i have attached my code also. Please 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','senthil') or die();
my $sh2=$db->prepare("select code,name from level ");
$sh2->execute() or die();
my @name;
while (my $row = $sh2->fetchrow_arrayref)
{
push @name, $row;
}
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(0..10) {
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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.