in reply to creating multiple widgets at runtime

You should call MainLoop after the while loop, not within it. I'm pretty sure that MainLoop should only be called once within a given Tk program.

Replies are listed 'Best First'.
Re^2: creating multiple widgets at runtime
by pg (Canon) on Jul 25, 2005 at 04:49 UTC

    Just to clarify, this particular MainLoop should be removed not moved ;-)

Re^2: creating multiple widgets at runtime
by GrandFather (Saint) on Jul 25, 2005 at 05:12 UTC

    Not alltogether true. The following is ok and can be usefull:

    use strict; use warnings; use Tk; my $main = MainWindow->new (); $main->Button (-text => "Close", -command => sub{$main->destroy ();})- +>pack(); MainLoop; $main = MainWindow->new (); $main->Button (-text => "Close too", -command => sub{$main->destroy () +;})->pack(); MainLoop;

    Perl is Huffman encoded by design.
      Hmm, how could this be useful? Can't you do the same with a Toplevel and only one MainLoop?

        In a context where you want to grab a chunk of information from the user a very light weight "open window, grab data, close window" is useful. In that context you don't want to go hunting for the $main that you may, or may not, have used before.

        I use this trick in apps that are essentially command line (or run from desktop short cuts) that sometimes need a little more info. It lets me write one utility that I can drag and drop onto, have snoop stuff out of the clipboard, or (if the other strategies fail) ask for the required info.


        Perl is Huffman encoded by design.