Eric has asked for the wisdom of the Perl Monks concerning the following question:
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.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Modifying Tk widgets via references
by my_nihilist (Sexton) on Mar 17, 2008 at 21:29 UTC | |
by Eric (Initiate) on Mar 17, 2008 at 21:38 UTC | |
Re: Modifying Tk widgets via references
by my_nihilist (Sexton) on Mar 17, 2008 at 21:53 UTC | |
Re: Modifying Tk widgets via references
by zentara (Archbishop) on Mar 18, 2008 at 13:46 UTC |
Back to
Seekers of Perl Wisdom