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;
In reply to Updating table in the canvas by kartiksharma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |