13.22. 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. For complete details, see Chapter 15, "Anatomy of the MainLoop" and Chapter 17, "Images and Animations". To have the program sleep for x number of milliseconds, call after with the number of milliseconds:
You almost never want to do this, as the event loop is blocked.
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);
$id = $widget->afterIdle(callback);
$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.
Copyright © 2002 O'Reilly & Associates. All rights reserved.