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


In reply to Re: Perl::Tk Problems with creating widgets using a loop by kcott
in thread Perl::Tk Problems with creating widgets using a loop by Microcebus

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.