The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tk::after - Execute a command after a time delay

SYNOPSIS

$widget->after(ms)

$widget->after(ms?,callback?)

$widget->afterCancel(id)

$widget->afterIdle(?callback?)

$widget->afterInfo?(id)?

DESCRIPTION

This command is used to delay execution of the program or to execute a command in background sometime in the future. It has several forms, depending on the first argument to the command:

after(ms)

Ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to events.

after(ms?,callback?)

In this form the command returns immediately, but it arranges for callback be executed ms milliseconds later as an event handler. The callback will be executed exactly once, at the given time. The command will be executed in context of $widget. If an error occurs while executing the delayed command then the Tk::Error mechanism is used to report the error. The after command returns an identifier that can be used to cancel the delayed command using afterCancel.

afterCancel(id)

Cancels the execution of a delayed command that was previously scheduled. Id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by id has already been executed then the after cancel command has no effect.

afterCancel(callback)

This command also cancels the execution of a delayed command. The callback arguments is compared with pending callbacks, if a match is found, that callback is cancelled and will never be executed; if no such callback is currently pending then the afterCancel has no effect. This form is not robust in perl/Tk - its use is deprecated.

afterIdle(callback)

Arranges for callback to be evaluated later as an idle callback. The script will be run exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that can be used to cancel the delayed command using afterCancel. If an error occurs while executing the script then the Tk::Error mechanism is used to report the error.

afterInfo?(id)?

This command returns information about existing event handlers. If no id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the after command for this MainWindow. If id is supplied, it specifies an existing handler; id must have been the return value from some previous call to after and it must not have triggered yet or been cancelled. In this case the command returns a list with two elements. The first element of the list is the callback associated with id, and the second element is either idle or timer to indicate what kind of event handler it is.

The after(ms) and afterIdle forms of the command assume that the application is event driven: the delayed commands will not be executed unless the application enters the event loop. In applications that are not normally event-driven, the event loop can be entered with the vwait and update commands.

SEE ALSO

Tk::callbacks

KEYWORDS

cancel, delay, idle callback, sleep, time