after(3pm)
π after(3pm) β Tk::after π
β¨ NAME β¨
Tk::after β execute a command after a time delay π
πΈ SYNOPSIS πΈ
$widget->after(ms)
$id = $widget->after(ms?,callback?)
$id = $widget->repeat(ms?,callback?)
$widget->afterCancel($id)
$id = $widget->afterIdle(callback)
$widget->afterInfo?($id)?
$id->time(?delay?)
π DESCRIPTION π
Okay bestie, this method is for delaying your program or running a callback in the background sometime in the future. No cap. In perl/Tk, $widget->after is implemented via the class Tk::After, and callbacks are associated with $widget, and they get automatically cancelled when the widget is destroyed. There's an almost identical interface, but without automatic cancel and without repeat, provided via the Tk::after method. Iykyk. π¦
π§ Internal Details π§
The internal Tk::After class has this synopsis:
$id = Tk::After->new($widget, tid, $time, 'once', callback);
$id = Tk::After->new($widget, tid, $time, 'repeat', callback);
$id->cancel;
$id->time(?delay?);
$id is a Tk::After object, an array of 5 elements:
$widgetis the parent widget reference. π«Άtidis the internal timer id, a unique string. π$timeis the string'idle', representing an idle queue timer, or an integer millisecond value. β³onceorrepeatspecifies whether the timer is a one-time after event, or a repeatingrepeatevent. πcallbackspecifies a Perl/TkTk::Callbackobject. π
β° Changing a repeat timer interval β°
It's possible to change a repeat timer's delay value, or even cancel any timer, using the time method. If delay is specified and non-zero, a new timer delay is established. If delay is zero, the timer event is canceled just as if $id->cancel were invoked. In all cases, the current millisecond timer delay is returned. β¨
Note: the new timer delay will take effect on the subsequent timer event β this command will not cancel the pending timer event and re-issue it with the new delay time. So don't @ me. π
The after() method has several forms as follows: π
$widget->after(ms)β bestie,mshas to be an integer that gives a time in milliseconds. The command sleeps formsmilliseconds and then returns. While it's sleeping, the application does not respond to events. π€$widget->after(ms,callback)β this form returns immediately, but it sets upcallbackto runmsmilliseconds later as an event handler. The callback runs exactly once, at the given time. The command runs in context of$widget. If an error happens while running the delayed command, theTk::Errormechanism reports it. The after command returns an identifier (an object in the perl/Tk case) that you can use to cancel the delayed command withafterCancel. π$widget->repeat(ms,callback)β returns immediately, but arranges forcallbackto runmsmilliseconds later as an event handler. Aftercallbackruns, it gets re-scheduled to run again in a futherms, and so on until it is cancelled. π$widget->afterCancel($id)and$id->cancelβ cancels the execution of a delayed command that was previously scheduled.$idtells which command should be canceled; it must have been the return value from a previous after command. If the command given by$idalready ran (and is not scheduled to run again), thenafterCancelhas no effect. π«$widget->afterCancel(callback)β not robust in perl/Tk β its use is deprecated. This command should also cancel the execution of a delayed command. Thecallbackargument 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 theafterCancelhas no effect. β οΈ$widget->afterIdle(callback)β arranges forcallbackto be evaluated later as an idle callback. The script runs exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that you can use to cancel the delayed command withafterCancel. If an error happens while running the script, theTk::Errormechanism reports it. π$widget->afterInfo?($id)?β returns info about existing event handlers. If you don't supply$id, the command returns a list of the identifiers for all existing event handlers created by theafterandrepeatcommands for$widget. If$idis supplied, it specifies an existing handler;$idmust have been the return value from some previous call toafterorrepeatand it must not have triggered yet or been cancelled. In this case the command returns a list with three elements. The first element of the list is the callback associated with$id, the second element is eitheridleor the integer timer millisecond value to indicate what kind of event handler it is, and the third is a stringonceorrepeatto differentiate an after from a repeat event. π
Both the after(ms) and afterIdle forms assume the app is event driven: those delayed commands won't run unless the application enters the event loop. If your app isn't normally event-driven, you can enter the event loop with the vwait and update commands. π
π SEE ALSO π
Tk::Error Tk::callbacks
π KEYWORDS π
cancel, delay, idle callback, sleep, time
perl v5.40.1 π 2025-04-13 β that's the vibe, bestie! πβ¨
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms