📄 after.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Tk::after - Execute a command after a time delay</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>Tk::after - Execute a command after a time delay</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#internal_details">Internal Details</a></li>
</ul>
<li><a href="#changing_a_repeat_timer_interval">Changing a <strong>repeat</strong> timer interval</a></li>
<li><a href="#the_after___method_has_several_forms_as_follows_">The <code>after()</code> method has several forms as follows:</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#keywords">KEYWORDS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tk::after - Execute a command after a time delay</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p> <em>$widget</em>-><strong>after</strong>(<em>ms</em>)</p>
<p> <em>$id</em> = <em>$widget</em>-><strong>after</strong>(<em>ms</em>?,<em>callback</em>?)</p>
<p> <em>$id</em> = <em>$widget</em>-><strong>repeat</strong>(<em>ms</em>?,<em>callback</em>?)</p>
<p> <em>$widget</em>-><strong>afterCancel</strong>(<em>$id</em>)</p>
<p> <em>$id</em> = <em>$widget</em>-><strong>afterIdle</strong>(<em>callback</em>)</p>
<p> <em>$widget</em>-><strong>afterInfo</strong>?(<em>$id</em>)?</p>
<p> <em>$id</em>-><strong>time</strong>(?<em>delay</em>?)</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This method is used to delay execution of the program or to execute
a callback in background sometime in the future.</p>
<p>In perl/Tk <em>$widget</em>-><strong>after</strong> is implemented via the class <code>Tk::After</code>,
and callbacks are associated with <em>$widget</em>, and are automatically cancelled
when the widget is destroyed. An almost identical interface, but without
automatic cancel, and without repeat is provided via Tk::after method.</p>
<p>
</p>
<h2><a name="internal_details">Internal Details</a></h2>
<p>The internal Tk::After class has the following synopsis:</p>
<pre>
<span class="variable">$id</span> <span class="operator">=</span> <span class="variable">Tk::After</span><span class="operator">-></span><span class="variable">new</span><span class="operator">(</span><span class="variable">$widget</span><span class="operator">,</span> <span class="variable">tid</span><span class="operator">,</span> <span class="variable">$time</span><span class="operator">,</span> <span class="string">'once'</span><span class="operator">,</span> <span class="variable">callback</span><span class="operator">);</span>
<span class="variable">$id</span> <span class="operator">=</span> <span class="variable">Tk::After</span><span class="operator">-></span><span class="variable">new</span><span class="operator">(</span><span class="variable">$widget</span><span class="operator">,</span> <span class="variable">tid</span><span class="operator">,</span> <span class="variable">$time</span><span class="operator">,</span> <span class="string">'repeat'</span><span class="operator">,</span> <span class="variable">callback</span><span class="operator">);</span>
<span class="variable">$id</span><span class="operator">-></span><span class="variable">cancel</span><span class="operator">;</span>
<span class="variable">$id</span><span class="operator">-></span><span class="keyword">time</span><span class="operator">(</span><span class="regex">?delay?</span><span class="operator">);</span>
</pre>
<p>$id is a Tk::After object, an array of 5 elements:</p>
<p><em>$widget</em> is the parent widget reference.</p>
<p><em>tid</em> is the internal timer id, a unique string.</p>
<p><em>$time</em> is the string 'idle', representing an idle queue timer, or a
integer millisecond value.</p>
<pre>
I<once> or I<repeat> specifies whether the timer is a one-time B<after>
event, or a repeating B<repeat> event.</pre>
<p><em>callback</em> specifies a Perl/Tk Tk::Callback object.</p>
<p>
</p>
<hr />
<h1><a name="changing_a_repeat_timer_interval">Changing a <strong>repeat</strong> timer interval</a></h1>
<p>It's posible to change a <strong>repeat</strong> timer's delay value, or even cancel
any timer, using the <strong>time</strong> method. If <em>delay</em> is specified and
non-zero, a new timer delay is established. If <em>delay</em> is zero the
timer event is canceled just as if <em>$id</em>-><strong>cancel</strong> were invoked.
In all cases the current millisecond timer delay is returned.</p>
<p>Note: the new timer delay will take effect on the <em>subsequent</em> timer
event - this command will not cancel the pending timer event and
re-issue it with the new delay time.</p>
<p>
</p>
<hr />
<h1><a name="the_after___method_has_several_forms_as_follows_">The <a href="#item_after"><code>after()</code></a> method has several forms as follows:</a></h1>
<dl>
<dt><strong><a name="item_after"><em>$widget</em>-><strong>after</strong>(<em>ms</em>)</a></strong>
<dd>
<p>The value <em>ms</em> must be an integer giving a time in milliseconds.
The command sleeps for <em>ms</em> milliseconds and then returns.
While the command is sleeping the application does not respond to
events.</p>
</dd>
</li>
<dt><strong><em>$widget</em>-><strong>after</strong>(<em>ms</em>,<em>callback</em>)</strong>
<dd>
<p>In this form the command returns immediately, but it arranges
for <em>callback</em> be executed <em>ms</em> 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 <em>$widget</em>.
If an error occurs while executing the delayed command then the
<a href="../../lib/Tk/Error.html">Tk::Error</a> mechanism is used to report the error.
The <strong>after</strong> command returns an identifier (an object in the perl/Tk
case) that can be used to cancel the delayed command using <strong>afterCancel</strong>.</p>
</dd>
</li>
<dt><strong><a name="item_repeat"><em>$widget</em>-><strong>repeat</strong>(<em>ms</em>,<em>callback</em>)</a></strong>
<dd>
<p>In this form the command returns immediately, but it arranges
for <em>callback</em> be executed <em>ms</em> milliseconds later as an
event handler. After <em>callback</em> has executed it is re-scheduled,
to be executed in a futher <em>ms</em>, and so on until it is cancelled.</p>
</dd>
</li>
<dt><strong><a name="item_aftercancel"><em>$widget</em>-><strong>afterCancel</strong>(<em>$id</em>)</a></strong>
<dt><strong><a name="item_cancel"><em>$id</em>-><strong>cancel</strong></a></strong>
<dd>
<p>Cancels the execution of a delayed command that
was previously scheduled.
<em>$id</em> indicates which command should be canceled; it must have
been the return value from a previous <strong>after</strong> command.
If the command given by <em>$id</em> has already been executed (and
is not scheduled to be executed again) then <strong>afterCancel</strong>
has no effect.</p>
</dd>
</li>
<dt><strong><em>$widget</em>-><strong>afterCancel</strong>(<em>callback</em>)</strong>
<dd>
<p><em>This form is not robust in perl/Tk - its use is deprecated.</em>
This command should also cancel the execution of a delayed command.
The <em>callback</em> argument 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 <strong>afterCancel</strong> has no effect.</p>
</dd>
</li>
<dt><strong><a name="item_afteridle"><em>$widget</em>-><strong>afterIdle</strong>(<em>callback</em>)</a></strong>
<dd>
<p>Arranges for <em>callback</em> 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 <strong>afterCancel</strong>.
If an error occurs while executing the script then the
<a href="../../lib/Tk/Error.html">Tk::Error</a> mechanism is used to report the error.</p>
</dd>
</li>
<dt><strong><a name="item_afterinfo"><em>$widget</em>-><strong>afterInfo</strong>?(<em>$id</em>)?</a></strong>
<dd>
<p>This command returns information about existing event handlers. If no
<em>$id</em> argument is supplied, the command returns a list of the
identifiers for all existing event handlers created by the <strong>after</strong>
and <strong>repeat</strong> commands for <em>$widget</em>. If <em>$id</em> is supplied, it
specifies an existing handler; <em>$id</em> must have been the return value
from some previous call to <strong>after</strong> or <strong>repeat</strong> and 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 <em>$id</em>, the second element is either <strong>idle</strong>
or the <em>integer</em> timer millisecond value to indicate what kind of
event handler it is, and the third is a string <em>once</em> or <em>repeat</em> to
differentiate an <strong>after</strong> from a <strong>repeat</strong> event.</p>
</dd>
</li>
</dl>
<p>The <strong>after</strong>(<em>ms</em>) and <strong>afterIdle</strong> 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 <strong>vwait</strong> and <strong>update</strong> commands.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Tk/Error.html">Tk::Error</a>
<a href="../../lib/Tk/callbacks.html">Tk::callbacks</a></p>
<p>
</p>
<hr />
<h1><a name="keywords">KEYWORDS</a></h1>
<p>cancel, delay, idle callback, sleep, time</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -