# Calculate the pixels and divide by 100 if ($first_start == "1"){ $tot_pix = $x * $y; $one_hunderd = $tot_pix / 100; } # Loop for drawing all for ($width = 0; $width < $x; $width++) { for ($height = 0; $height < $y; $height++) { # Define the exact coordinates to place the pixel $width_pos = $width + 1; $height_pos = $height + 1; $width_pos2 = $width + 2; $height_pos2 = $height + 2; $canvas->createRectangle($width_pos * $multipli ,$height_pos * $multipli , $width_pos2 *$multipli , $height_pos2 * $multipli , -fill => 'black'); } } } # If it is not the first time in this subroutine, start the thread if ($first_start == "1"){ my $thr1 = threads->create(\&progress_calc, $tot_pix, $one_hunderd, $passed_pix); } #add one to the variable $passed_pix += 1; # If it is not the first time, Join the thread. if ($first_start == "1"){ $thr1->join(); } } } #call the subroutine hide_progress(); #set the variables when exiting the subroutine $first_start = "1"; $passed_pix = 0; } #subroutine for the progress bar sub progress_calc { # Calculations for progress bar $var1 = $percent_done; $var2 = $passed_pix; $var3 = $one_hunderd; while ($var1 <= 100) { #do some math to define the percent done and update the progress bar. $var1= $var2 / $var3; $win_prog->update(); } } #sub to show the progress bar sub show_progress { $win_prog->deiconify(); $win_prog->raise(); $win_prog->update(); } #sub to hide the progress bar sub hide_progress { $win_prog->withdraw(); }