Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Tk progress bar

by JSchmitz (Canon)
on May 12, 2002 at 17:44 UTC ( [id://166010]=perlquestion: print w/replies, xml ) Need Help??

JSchmitz has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get TK::Progress bar going for a project I am working on. This code runs fine under Win32 but hoses with no errors under Linux which is where I need this to run. When executed it waits a few secs then just returns the command prompt.
#!/usr/bin/perl use Tk; use Tk::ProgressBar; my $mw = MainWindow->new(-title => 'Processing'); $Progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [0, 'green', 50, 'yellow' ,80, 'red'], -variable => \$percent_done )->pack(-fill => 'x'); $mw->Button(-text => 'Go!', -command=> sub { for ($i =0; $i < 1000; $i++) { $percent_done = $i/10; print "$i\n"; $mw->update; } })->pack(-side => 'bottom'); Mainloop;
I intially thought that maybe the mod was not installed correctly but I checked and it was fine. I am pretty sure it is in the Tk standard library. Anyways it shows as being up to date:

CPAN Terminal>m Tk::ProgressBar
0001 Tk::ProgressBar 1.04 ACH
CPAN Terminal>install 0001
Installing: Tk::ProgressBar
Module Tk::ProgressBar already up to date; won't install
without force!
All cached data has been flushed.

any help would be appreciated!

cheers!

Jeff

Replies are listed 'Best First'.
Re: Tk progress bar
by alien_life_form (Pilgrim) on May 12, 2002 at 18:11 UTC
    Greetings,

    The following version:

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ProgressBar; my $percent_done=0; my $mw = MainWindow->new(-title => 'Processing'); my $Progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [ 0, 'green', 50, 'yellow' , 80, 'red', ], -variable => \$percent_done )->pack(-fill => 'x'); $mw->Button(-text => 'Go!', -command=> sub { my $i; for ($i =0; $i < 1000; $i++) { $percent_done = $i/10; print STDOUT "$i\n"; $mw->update; } })->pack(-side => 'bottom'); MainLoop();
    Works like a beaut on my machine. The most dramatic change is :
    Mainloop gets changed in MainLoop().

    The way I made it to work, though, was by using "strict" and "warnings" ...

    Cheers,
    alf


    You can't have everything: where would you put it?
Re: Tk progress bar
by hagus (Monk) on May 12, 2002 at 23:22 UTC
    You may wish to check out the progress bar I uploaded as a node ... this does work on Linux. Might give you some ideas.

    progresWidget class

    --
    Ash OS durbatulk, ash OS gimbatul,
    Ash OS thrakatulk, agh burzum-ishi krimpatul!
    Uzg-Microsoft-ishi amal fauthut burguuli.

Warnings, strict
by The Alien (Sexton) on May 12, 2002 at 18:12 UTC
    Others are probably writing this just as I am, but you should probably check the output with at least -w and probably use strict; ... I haven't used that module before, but I'd guess if it isn't working you should at least get a warning out of it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://166010]
Front-paged by JSchmitz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found