Hello people,
I have just started with perl TK and got struck. I am making a small game for practice in which I have a table on one tab and two text fields on another tab for entering rows and columns of the table.
When I enter rows and columns value in the text field and press the button, the command says that it will update the rows and columns values of the table and should show a new table with a new value. But, the table remains as it is and is not updating with new rows and columns.
Please help me with this as I am new to Perl and not able to solve this issue. I don't know how should I return the values from event subroutine of button
use strict;
use warnings;
use Tk;
use Tk::NoteBook;
my $rows;
my $columns;
#creating main window and font
my $font = '{Calibri} 11';
my $mw=new MainWindow(-title => "Tab one",-background=>'Black');
$mw->minsize(qw(800 800));
#creating canvas
my $canvas1 = $mw -> Canvas(-width=>800,-height=>550,
-borderwidth => 2,
-relief=>"raised",-bg=>"red")->pack();
my $canvas2 = $mw -> Canvas(-width=>800,-height=>250,
-borderwidth => 2,
-relief=>"raised",-bg=>"#8E8F97")->pack();
#creating table in canvas 1
my $table = $canvas1->Table(-rows => $rows,-columns => $columns,
-scrollbars => 'se',-takefocus => 0)->pack( -expand => 1, -fill =>
+ 'both' );
#Arranging canvas 2
my $frame1= $canvas2->Frame(-relief=>'groove',-borderwidth=>3, -bg=>'b
+lue')->pack(-side=>'top',-fill=>'x');
my $lb1= $frame1->Label(-text=>'Enter number of rows: ',-bg=>'blue',-f
+oreground=>'white')->pack(-side=>'left');
my $tf1= $frame1->Entry(-width=>8,-bg=>'white')->pack(-side=>'left',-p
+ady=>3);
my $frame2= $canvas2->Frame(-relief=>'groove',-borderwidth=>3, -bg=>'b
+lue')->pack(-side=>'top',-fill=>'x');
my $lb2= $frame2->Label(-text=>'Enter number of Columns: ',-bg=>'blue'
+,-foreground=>'white')->pack(-side=>'left');
my $tf2= $frame2->Entry(-width=>8,-bg=>'white')->pack(-side=>'left',-p
+ady=>3);
my $frame3= $canvas2->Frame(-relief=>'groove',-borderwidth=>3, -bg=>'b
+lue')->pack(-side=>'top',-fill=>'x');
my $btn3= $frame3->Button(-text=>"Enter", -command =>\&push_button)->p
+ack();
#Filling the tabel according to rows and columns
for(my $row=0;$row<$rows;$row++)
{
for(my $column=0;$column<$columns;$column++)
{
my $label=$canvas1->Label(-text=>"$row $column",-height=>2,-wi
+dth=>10,-relief=>"raised",-background=>'white');
my $old = $table->put($row,$column,$label);
}
}
sub push_button {
$rows= $tf1->get();
$columns= $tf2->get();
}
MainLoop;
-
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.