Hi, I am currently running into a problem while creating a Perl/Tk application. The programme will potentially run for a rather long time and I'd like to have the user having some feedback that something is still happening. So a progress bar and a status line combined in a Toplevel widget seemed to be a good idea, but I often need more than one. Being lazy, I placed the widget creation, update and destroy routines into a module and access it from other modules. The reference to the Toplevel widget is returned and saved in a variable.
When using only one widget, everything is fine.
But when creating two, I am running into problems. Creating the widgets is no problem, but when I update one widget (using its unique reference), both Toplevel widgets are updated at the same time, overwriting the content of the first with the content of the second.
I am a bit confused why this happens and would really appreciate any help or guidance.

Here's the principle structure:

package Basics::progress_bar;
<stuff>
sub progress_bar {
my $tl= $mw->Toplevel();
...<stuff>...
return ($tl);
}

sub update {
my %args = @_;
...<redefine some variables>...
#$args{widget} should contain the unique reference that was returned above.
$args{widget}->update;
}
1;


And here are the widget calls from within another module:
$progress_bar_ref_a = &progress_bar(parameters);
$progress_bar_ref_b = &progress_bar(other parameters);

Updating the widget from within another module:
&update(widget => $progress_bar_ref_b,
additional parameters);

Although specifying the reference for the 2nd instance, both widgets will be updated with the new parameters.

In reply to Modifying Tk widgets via references by Eric

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.