Without showing your code, we can only guess as to what you are actually doing. The advice to make new toplevel windows is ok, but you may find memory increasing for every new toplevel you create.

It works basically like this. You need one Mainloop running, so you need to keep 1 mainwindow going, even if it is withdrawn from view. Once you have the Mainloop, you can create any number of toplevel windows controlled by that loop. If you start creating new toplevels, then destroying them, and you see memory gain, you can go to the more advanced method using packForget. You can take any window, withdraw it, run packForget on all it's packChildren, repack it with fresh widgets, then raise it back up. If you are going to juggle alot windows with different widgets packed into them, it is best to use the packForget method, so you have fewer windows created-destroyed.

The idea is you can reuse existing windows. Furthermore, you can reuse any widgets by withdrawing them, reconfiguring them, then repacking them. Here is a basic example: (I didn't reuse the cb widgets, but reused the frame and maindow.

#!/usr/bin/perl use warnings; use strict; use Tk; my $top = new MainWindow; my @counts = ('a'..'z'); my %cbuttons; my $frame = $top->Frame()->pack(); setup_page(); $top->Button(-text => "packForget", -command => sub{ my @w = $frame->packSlaves; foreach (@w) { $_->packForget; } })->pack(); $top->Button(-text => "repack", -command => sub{ &setup_page })->pack(); $top->Button(-text => "Exit", -command => sub {exit})->pack; MainLoop; sub setup_page{ for (1..4){ my $text = shift @counts; $cbuttons{$_}{'cb'} = $frame->Checkbutton( -text => $text, -variable => \$cbuttons{$_}{'val'}, -command => \&SetState, )->pack; } }

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

In reply to Re: perlTk opening new window by zentara
in thread perlTk opening new window by wisemonkey

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.