You are a beginner, so I'm going to show you some of the tricks you need to make your program work as you want. First of all, the code you presented is far from workable, as a first criticism you are not using Notebook tabs and the Canvas properly. You seem to be packing your table widgets into separate canvases, somehow hoping it will function. It won't work your way, as drag'ndrop on the canvases will not work out of the tables the way they are packed.

I have a little example here, which I worked up for you, with comments trying to explain what is going on. It should pretty much do what you want, but I leave it to you to setup the rectangular grid within the canvas, and managing the drag'n'drop positions. The fake data I setup in the tables can easily be changed to which position in your rectangular canvas grid you wish to place them. There is still alot of detailed work to be done on the Canvas portion .... setting up the canvas rectangular grid depending on how many entries are in your tables, and checking for correctness , etc, etc. Good Luck, the game is a nice concept for teaching.

#!/usr/bin/perl -w use warnings; use strict; use Tk; use Tk::NoteBook; require Tk::Pane; use Tk::LabEntry; my ($dx,$dy); my $mw = MainWindow->new; $mw->geometry( "600x500"); $mw->title("My New Game"); # ###program parameter hash my %tools = ( 'program1' => { 'PARM1' => 1, 'PARM2' => 'n', 'PARM3' => 'y', 'PARM4' => 'n', 'PARM5' => 'y', 'PARM6' => 'n', 'PARM7' => 'y', 'PARM8' => 'n', 'PARM9' => 'y', 'PARM10' => 'n' }, 'program2' => { 'PARM1' => 1, 'PARM2' => 2, 'PARM3' => 3, 'PARM4' => 4, 'PARM5' => 5, 'PARM6' => 6, 'PARM7' => 7, 'PARM8' => 8, 'PARM9' => 9, 'PARM10' => 10 }); my $tframe = $mw->Frame->pack(-fill=>'both'); my $mframe = $mw->Frame->pack(-expand=>1,-fill=>'both'); $tframe->Label(-text=>'My Game')->pack(); + ## create notebook my $book = $mframe->NoteBook( -dynamicgeometry=>0) ->pack(-expand=>1,-fill=>'both'); #####program1####### my $tab_cnt=1; my %panes; for my $tab (keys %tools){ ##create tab,scroll pane,frames my $tab_tab = $book->add("Game $tab_cnt", -raisecmd=> sub{ # $tab_spane->configure( -scrollregion => [0,0,$book->reqwidth +,$book->reqheight]); $mw->update}, -label => "$tab"); #->pack(-expand=>1,-fill=>'both'); # packing a page add causes a weird error my $tab_spane = $tab_tab->Scrolled('Pane', -background=>'slate grey', -scrollbars => 'osoe', )->pack(-expand=>1, -fill=>'both'); my $tab_frame1=$tab_spane->Frame( -background=>'blue')->pack(-side=>'left',-expand=>1,-fill=>'both +',-padx=>15); my $tab_frame2=$tab_spane->Frame( -background=>'red')->pack(-side=>'bottom',-anchor=>'s',-fill=>'x +'); $tab_cnt++; #create columns my $tab_column1 = $tab_frame1->Frame()->pack(-side=>'left',-exp +and=>1,-fill=>'both'); my $tab_column2 = $tab_frame2->Frame()->pack(-side=>'right',-ex +pand=>1,-fill=>'both'); ##now fill frames my $parm_cnt=1; print "Processing tool: $tab\n"; foreach my $parm (custom_sort(\%{$tools{$tab}})) { print " $parm = $tools{$tab}{$parm}\n"; if ($parm_cnt < 6 ){ my $tab_test=$tab_column1->LabEntry(-label => "$parm=") +; $tab_test->Subwidget('entry')->configure(-textvariable => \$t +ools{$tab}{$parm} ); $tab_test->configure(-labelPack=>[-side=>'left']); $tab_test->pack(-anchor=>'e'); } else { my $tab_test=$tab_column2->LabEntry(-label => "$parm=") +; $tab_test->Subwidget('entry')->configure(-textvariable => \$t +ools{$tab}{$parm} ); $tab_test->configure(-labelPack=>[-side=>'left']); $tab_test->pack(-anchor=>'e'); } $parm_cnt++; } #######run button############# my $run = $tab_tab->Button( -text => "\n Run $tab \n ", -command => [\&run, $tab], -background=>'slate grey')->pack; } # end of page creation loop # now add your canvas which will host the actual game my $game_tab = $book->add("Game Canvas", -raisecmd=> sub{ $mw->update}, -label => " Actual Game Canvas "); # make the actual Canvas my $scan = $game_tab->Scrolled('Canvas', -bg => 'black')->pack(-expan +d=>1, -fill=>'both'); # get the real canvas of the scrolled widget my $realcan = $scan->Subwidget('scrolled'); $realcan->bind('move', '<1>', sub {&mobileStart();}); $realcan->bind('move', '<B1-Motion>', sub {&mobileMove();}); $realcan->bind('move', '<ButtonRelease>', sub {&mobileStop();}); MainLoop; ####################### subs ################################# sub run { print "@_\n"; my $program = shift; # clear out any old game data by tag $scan->delete('move'); # switch to Game tab $book->raise( 'Game Canvas'); # I have the proper dereferencing here, # to show you how it would work my $y = 10; #starting print point foreach my $parm (custom_sort(\%{$tools{$program}})) { print " $parm = $tools{$program}{$parm}\n"; $scan->createText(50,$y, -text => "$parm @ $tools{$program}{$parm}", -fill =>'yellow', -anchor => 'nw', -font => 'big', -tags=> ['move'] ); $y +=50; } # set scroll region for canvas $scan->configure(-scrollregion=>[$scan->bbox("all")]); } sub custom_sort { my $hash = shift; return map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map { [ $_, /(\w+)(\d+)$/ ] } keys %$hash; } sub mobileStart { my $ev = $realcan->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $realcan->raise('current'); print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $realcan->XEvent; $realcan->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); print "MOVING-> $dx $dy\n"; } sub mobileStop{&mobileMove;}

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

In reply to Re: Updating table in the canvas by zentara
in thread 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.