"... 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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|