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;

In reply to Updating table in the canvas by kartiksharma

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.