Aboveyou has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I use the Destroy func to delete diffrent wingets but when i try to create new widget in the same place (same specific location) it apper in diffrent place any idea why? and how can i solve this issue? example will be great thanks.

Replies are listed 'Best First'.
Re: TK Destroy func
by halfcountplus (Hermit) on Jun 12, 2009 at 20:10 UTC
    $vary's scope is wrong. If you move "my $vary = 0" into sub dude where "my $varx" is, this will work more like the way you want (I promise). The way you have it, the value of $vary increases every time you push the button, instead of being set back to zero like $varx.

    You should remove the "my $varx, my $vary" from the top. You only need them in the for loop of sub dude. You should start learning to program with "use strict" on. That means declaring all your variables the first time with my. I think that will also help prevent you from making these kind of mistakes. So the first part of this program would look like:
    #!/usr/bin/perl -w use strict; use Tk; my $MainWindow = MainWindow->new; $MainWindow->geometry("420x420"); $MainWindow->configure(-background => "black"); my $m = 0; my $bfa = 0; my $n=0; my @ButtFunc; my @montharr; my @Jularr;
    Getting used to "use strict" is important as apparently the next release of perl will not give you a choice about it. Once you start, it is easy and there is never a reason to go back.

    Nice geometry ;) EST

    PS. put line breaks in your code around 80 characters or something, at least when you post. I can't stand scrolling horizontally...
Re: TK Destroy func
by Aboveyou (Acolyte) on Jun 12, 2009 at 19:40 UTC
    first click - boxes will be on top secound click - boxes will be bottom i want them to stay in the same place (top)
    use Tk; $MainWindow = MainWindow->new; $MainWindow->geometry("420x420"); $MainWindow->configure(-background => "black"); $m = 0; $bfa = 0; my $vary = 0; my $varx = 0; my $n=0; $MainWindow->Button(-font => "Ariel 8 bold", -relief => 'groove', -tex +t => "click", -width => 14, -height => 0, -command => \&dude)->place( + -x => 200, -y => 385); sub dude { foreach $WidgetDestroy(@ButtFunc) { if (defined ($ButtFunc[$n])) { $WidgetDestroy->destroy; } if (undef ($ButtFunc[$n])) { print "hello"; } ++$n; } for (my $i=0;$i<6;$i++) { my $varx = 0; for (my $j=0; $j<7; $j++) { $ButtFunc[$bfa] = $MainWindow->Button(-font => "Ariel +8 bold", -relief => 'groove',-background => 'white', -text => $montha +rr[$m], -width => 15, -height => 2, -command => [ \&OpenTab, $Jularr[ +$m]])->place( -x => $varx, -y => $vary); $varx = $varx + 98; ++$m; ++$bfa; } $vary = $vary + 43; } } MainLoop;
Re: TK Destroy func
by halfcountplus (Hermit) on Jun 12, 2009 at 19:22 UTC
    Post a *short* example of what you mean.