"... I could only find one answer about using threads ine that node, and I didn't understand it sorry."
Perhaps a look at the Perl Threads Tutorial might help.
Here's a technique for creating image data and updating a progress bar without using threads. I've made no attempt to integrate canvasses, rectangles, etc. This is a complete working script — you should be able to run it as is.
#!/usr/bin/env perl
use strict;
use warnings;
use Tk;
use Tk::Photo;
use Tk::ProgressBar;
my $mw = MainWindow->new();
$mw->geometry("200x200");
my $action_F = $mw->Frame()->pack(-side => 'bottom');
my $exit_B = $action_F->Button(-text => 'Exit', -command => sub { exit
+ })->pack;
my $image_F = $mw->Frame(
)->pack(-padx => 10, -pady => 10, -expand => 1, -fill => 'both');
my $progress_F = $mw->Frame(
)->pack(-padx => 10, -pady => 10, -expand => 0, -fill => 'x');
my ($image_height, $image_width) = (100, 100);
my $image = $image_F->Photo(-height => $image_height, -width => $image
+_width);
$image_F->Label(-image => $image)->pack;
my $pc_image_drawn = 0;
my $progress_PB = $progress_F->ProgressBar(-variable => \$pc_image_dra
+wn
)->pack(-fill => 'x');
for my $height (0 .. $image_height - 1) {
for my $width (0 .. $image_width - 1) {
$image->put('#ffcc33', -to => $width, $height);
$image->update; # called in inner loop for slow demonstration
+display
}
$pc_image_drawn = (($height + 1) / ($image_height)) * 100;
}
MainLoop;
|