in reply to Perl::Tk Problems with creating widgets using a loop
You're main problem here is that you're relying on the autovivification of the variable $status.
Every instance of that variable is the same one: $main::status. Any change you make in one widget will be propagated to all of them (via -variable=>\$status).
What you need is a separate lexical variable to be captured by the closure given by -command.
The first thing you need to do is add use strict; to the top of your code: immediately after #!/usr/bin/perl -w
Rerun your code and you'll get a series of warning messages highlighting what I've described above.
The next step is to add my in front of all the variables you've just been warned about (e.g. my $mw = MainWindow->new();).
I always find it's good practice to specify which widgets you are using so that Tk doesn't have to guess. You'll need something like:
use Tk; use Tk::Label; use Tk::Entry; use Tk::Checkbutton;
Basically, if you get a message like "assuming you meant XXX, then tell Tk exactly what you did mean. That way there won't be any surprises; you also get rid of a lot of annoying messages.
You may be able to work things out from here. If not, repost your updated code and all output and we can have a further look at it.
-- Ken
|
|---|