in reply to Creating a non-UI event in Perl/Tk

Unless I'm missing something, I don't think you even need to use the after(0,...). You can just call the sub directly.
#!/usr/bin/perl use Tk; use Tk::ProgressBar; my $mw = new Tk::MainWindow; my $p_bar = $mw->ProgressBar( -blocks => 1, -width => 20, -length => 200, -from => 0, -to => 100, -variable => \(my $foo), )->pack(); $foo = 0; #$mw->after(0,\&main_logic); &main_logic; MainLoop; sub main_logic { $mw->repeat(10, sub { $foo = ($foo + 1) % 100 }); }

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Creating a non-UI event in Perl/Tk
by radiantmatrix (Parson) on Sep 23, 2004 at 14:05 UTC
    If my main_logic loop was only working with widget operations, yes. It isn't -- it's doing significant I/O. The problem with the code above is that main_logic will run until completion (about 20 minutes on average) before MainLoop is called.

    While I could work some repeat magic, the resulting code is much less readable (I have about 300 lines of code in my main_logic loop).

    require General::Disclaimer;

    All code, unless otherwise noted, is untested

    "All it will give you though, are headaches after headaches as it misinterprets your instructions in the most innovative yet useless ways." - Maypole and I - Tales from the Frontier of a Relationship (by Corion)