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

Hi all, I have a perl/Tk application which lists files and updates disk usage every 5 minutes. At the moment, I have the following, but its seems rather clunky and the GUI itself does not have a very fluid feel to it. Is there a better way? Regards, Stacy. &disk_space; #check disk space &refresh_tally; #refresh GUI my $counter = 300; while (1) { #always true $counter -= 1; $frame->update; sleep 1; unless ($counter > 0) { &disk_space; &refresh_tally; $frame->update; $counter = 300; #reset counter } $frame->update; } MainLoop;

Replies are listed 'Best First'.
Re: Updating perl/Tk fluid-like
by kschwab (Vicar) on May 19, 2001 at 23:03 UTC
    Spawning events in Perl::Tk is probably better done with Tk::after. This allows them to be spawned at the top of the event loop, avoiding calls like sleep() that will block user input and screen updates to the gui.

    For recurring calls, Tk::after offers repeat().

    In your case, something like:

    $frame->repeat(30000,\&doit); sub doit { &disk_space; &refresh_tally; }
    You may also want to offer a refresh button if the user wishes to get the latest stats.

    See "perldoc Tk::callbacks" and "perldoc Tk::after" for more info.

      That is exactly what I was after! Thankyou.... Regards, Stacy.