Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

16.21. Time Delays

There are times when you'll want to be able to delay the program a bit before going on, or maybe you'll want to execute the same command every minute. To have the program sleep for x number of milliseconds, call after with the number of milliseconds:

$widget->after(milliseconds);

To specify a callback that will be called after so many milliseconds instead of waiting, send a callback as the second argument to after:

$id = $widget->after(milliseconds, callback);
# i.e.
$id = $widget->after(1000, \&do_something);

If you want to execute a subroutine after the program has been idle for a while, call afterIdle:

$id = $widget->afterIdle(callback);

To cancel the call to after or afterIdle, use afterCancel with the $id returned by after:

$widget->afterCancel($id);
# You can also do this:
$id->cancel();

You can have the program repeatedly call the same callback by using the repeat method:

$widget->repeat(milliseconds, callback);
# i.e.
$widget->repeat(600, \&update_status);

If you destroy $widget, any calls to after and repeat are automatically canceled for you.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata