canvas.html

来自「perl教程」· HTML 代码 · 共 1,385 行 · 第 1/5 页

HTML
1,385
字号
<dt><strong><a name="item_bind"><em>$canvas</em>-&gt;<strong>bind</strong>(<em>tagOrId</em>?, <em>sequence</em>? ?,<em>callback</em>?)</a></strong>

<dd>
<p>This method associates <em>callback</em> with all the items given by
<em>tagOrId</em> such that whenever the event sequence given by
<em>sequence</em> occurs for one of the items the callback will
be invoked.
This method is similar to the <strong>bind</strong> method except that
it operates on items in a canvas rather than entire widgets.
See <a href="../../lib/Tk/bind.html">the Tk::bind manpage</a> for complete details
on the syntax of <em>sequence</em> and the substitutions performed
on <em>callback</em> before invoking it.
If all arguments are specified then a new binding is created, replacing
any existing binding for the same <em>sequence</em> and <em>tagOrId</em>
(if the first character of <em>command</em> is ``+'' then <em>command</em>
augments an existing binding rather than replacing it).
In this case the return value is an empty string.
If <em>callback</em> is omitted then the method returns the <em>callback</em>
associated with <em>tagOrId</em> and <em>sequence</em> (an error occurs
if there is no such binding).
If both <em>callback</em> and <em>sequence</em> are omitted then the method
returns a list of all the sequences for which bindings have been
defined for <em>tagOrId</em>.</p>
</dd>
<p>The only events for which bindings may be specified are those related to
the mouse and keyboard (such as <strong>Enter</strong>, <strong>Leave</strong>,
<strong>ButtonPress</strong>, <strong>Motion</strong>, and <strong>KeyPress</strong>) or virtual events.
The handling of events in canvases uses the current item defined
in <a href="#item_ids_and_tags">ITEM IDS AND TAGS</a> above.  <strong>Enter</strong> and <strong>Leave</strong> events trigger for an
item when it becomes the current item or ceases to be the current item;
note that these events are different than <strong>Enter</strong> and <strong>Leave</strong>
events for windows.  Mouse-related events are directed to the current
item, if any.  Keyboard-related events are directed to the focus item, if
any (see the <a href="#item_focus">focus</a> method below for more on this).  If a
virtual event is used in a binding, that binding can trigger only if the
virtual event is defined by an underlying mouse-related or
keyboard-related event.</p>
<p>It is possible for multiple bindings to match a particular event.
This could occur, for example, if one binding is associated with the
item's id and another is associated with one of the item's tags.
When this occurs, all of the matching bindings are invoked.
A binding associated with the <strong>all</strong> tag is invoked first,
followed by one binding for each of the item's tags (in order),
followed by a binding associated with the item's id.
If there are multiple matching bindings for a single tag,
then only the most specific binding is invoked.
A <strong>continue</strong> in a callback terminates that
subroutine, and a <strong>break</strong> method terminates that subroutine
and skips any remaining callbacks for the event, just as for the
<strong>bind</strong> method.</p>
<p>If bindings have been created for a canvas window using the <strong>CanvasBind</strong>
method, then they are invoked in addition to bindings created for
the canvas's items using the <strong>bind</strong> method.
The bindings for items will be invoked before any of the bindings
for the window as a whole.</p>
<dt><strong><a name="item_canvasx"><em>$canvas</em>-&gt;<strong>canvasx</strong>(<em>screenx</em>?, <em>gridspacing</em>?)</a></strong>

<dd>
<p>Given a window x-coordinate in the canvas <em>screenx</em>, this method returns
the canvas x-coordinate that is displayed at that location.
If <em>gridspacing</em> is specified, then the canvas coordinate is
rounded to the nearest multiple of <em>gridspacing</em> units.</p>
</dd>
</li>
<dt><strong><a name="item_canvasy"><em>$canvas</em>-&gt;<strong>canvasy</strong>(<em>screeny, </em>?<em>gridspacing</em>?)</a></strong>

<dd>
<p>Given a window y-coordinate in the canvas <em>screeny</em> this method returns
the canvas y-coordinate that is displayed at that location.
If <em>gridspacing</em> is specified, then the canvas coordinate is
rounded to the nearest multiple of <em>gridspacing</em> units.</p>
</dd>
</li>
<dt><strong><a name="item_coords"><em>$canvas</em>-&gt;<strong>coords</strong>(<em>tagOrId </em>?<em>x0,y0 ...</em>?)</a></strong>

<dd>
<p>Query or modify the coordinates that define an item.
If no coordinates are specified, this method returns a list
whose elements are the coordinates of the item named by
<em>tagOrId</em>.
If coordinates are specified, then they replace the current
coordinates for the named item.
If <em>tagOrId</em> refers to multiple items, then
the first one in the display list is used.</p>
</dd>
</li>
<dt><strong><a name="item_create"><em>$canvas</em>-&gt;<strong>create</strong>(<em>type, x, y, </em>?<em>x, y, ...</em>?, ?<em>option, value, ...</em>?)</a></strong>

<dd>
<p>Create a new item in <em>$canvas</em> of type <em>type</em>.
The exact format of the arguments after <strong>type</strong> depends
on <strong>type</strong>, but usually they consist of the coordinates for
one or more points, followed by specifications for zero or
more item options.
See the subsections on individual item types below for more
on the syntax of this method.
This method returns the id for the new item.</p>
</dd>
</li>
<dt><strong><a name="item_dchars"><em>$canvas</em>-&gt;<strong>dchars</strong>(<em>tagOrId, first, </em>?<em>last</em>?)</a></strong>

<dd>
<p>For each item given by <em>tagOrId</em>, delete the characters, or coordinates,
in the range given by <em>first</em> and <em>last</em>, inclusive.
If some of the items given by <em>tagOrId</em> don't support
Text items interpret <em>first</em> and <em>last</em> as indices to a character,
line and polygon items interpret them indices to a coordinate (an x,y pair).
within the <code>item(s)</code> as described in <a href="#indices">INDICES</a> above.
If <em>last</em> is omitted, it defaults to <em>first</em>.
This method returns an empty string.</p>
</dd>
</li>
<dt><strong><a name="item_delete"><em>$canvas</em>-&gt;<strong>delete</strong>(?<em>tagOrId, tagOrId, ...</em>?)</a></strong>

<dd>
<p>Delete each of the items given by each <em>tagOrId</em>, and return
an empty string.</p>
</dd>
</li>
<dt><strong><a name="item_dtag"><em>$canvas</em>-&gt;<strong>dtag</strong>(<em>tagOrId, </em>?<em>tagToDelete</em>?)</a></strong>

<dd>
<p>For each of the items given by <em>tagOrId</em>, delete the
tag given by <em>tagToDelete</em> from the list of those
associated with the item.
If an item doesn't have the tag <em>tagToDelete</em> then
the item is unaffected by the method.
If <em>tagToDelete</em> is omitted then it defaults to <em>tagOrId</em>.
This method returns an empty string.</p>
</dd>
</li>
<dt><strong><a name="item_find"><em>$canvas</em>-&gt;<strong>find</strong>(<em>searchCommand, </em>?<em>arg, arg, ...</em>?)</a></strong>

<dd>
<p>This method returns a list consisting of all the items that
meet the constraints specified by <em>searchCommand</em> and
<em>arg</em>'s.
<em>SearchCommand</em> and <em>args</em> have any of the forms
accepted by the <strong>addtag</strong> method.
The items are returned in stacking order, with the lowest item first.</p>
</dd>
</li>
<dt><strong><a name="item_focus">focus</a></strong>

<dt><strong><em>$canvas</em>-&gt;<strong>focus</strong>(?<em>tagOrId</em>?)</strong>

<dd>
<p>Set the keyboard focus for the canvas widget to the item given by
<em>tagOrId</em>.
If <em>tagOrId</em> refers to several items, then the focus is set
to the first such item in the display list that supports the
insertion cursor.
If <em>tagOrId</em> doesn't refer to any items, or if none of them
support the insertion cursor, then the focus isn't changed.
If <em>tagOrId</em> is an empty
string, then the focus item is reset so that no item has the focus.
If <em>tagOrId</em> is not specified then the method returns the
id for the item that currently has the focus, or an empty string
if no item has the focus.</p>
</dd>
<p>Once the focus has been set to an item, the item will display
the insertion cursor and all keyboard events will be directed
to that item.
The focus item within a canvas and the focus window on the
screen (set with the <strong>focus</strong> method) are totally independent:
a given item doesn't actually have the input focus unless (a)
its canvas is the focus window and (b) the item is the focus item
within the canvas.
In most cases it is advisable to follow the <strong>focus</strong> widget
method with the <strong>CanvasFocus</strong> method to set the focus window to
the canvas (if it wasn't there already).</p>
<dt><strong><a name="item_gettags"><em>$canvas</em>-&gt;<strong>gettags</strong>(<em>tagOrId</em>)</a></strong>

<dd>
<p>Return a list whose elements are the tags associated with the
item given by <em>tagOrId</em>.
If <em>tagOrId</em> refers to more than one item, then the tags
are returned from the first such item in the display list.
If <em>tagOrId</em> doesn't refer to any items, or if the item
contains no tags, then an empty string is returned.</p>
</dd>
</li>
<dt><strong><a name="item_icursor"><em>$canvas</em>-&gt;<strong>icursor</strong>(<em>tagOrId, index</em>)</a></strong>

<dd>
<p>Set the position of the insertion cursor for the <code>item(s)</code> given by <em>tagOrId</em>
to just before the character whose position is given by <em>index</em>.
If some or all of the items given by <em>tagOrId</em> don't support
an insertion cursor then this method has no effect on them.
See <a href="#indices">INDICES</a> above for a description of the
legal forms for <em>index</em>.
Note:  the insertion cursor is only displayed in an item if
that item currently has the keyboard focus (see the widget
method <strong>focus</strong>, below), but the cursor position may
be set even when the item doesn't have the focus.
This method returns an empty string.</p>
</dd>
</li>
<dt><strong><a name="item_index"><em>$canvas</em>-&gt;<strong>index</strong>(<em>tagOrId, index</em>)</a></strong>

<dd>
<p>This method returns a decimal string giving the numerical index
within <em>tagOrId</em> corresponding to <em>index</em>.
<em>Index</em> gives a textual description of the desired position
as described in <a href="#indices">INDICES</a> above.
Text items interpret <em>index</em> as an index to a  character,
line and polygon items interpret it as an index to a coordinate (an x,y pair).
The return value is guaranteed to lie between 0 and the number
of characters, or coordinates, within the item, inclusive.
If <em>tagOrId</em> refers to multiple items, then the index
is processed in the first of these items that supports indexing
operations (in display list order).</p>
</dd>
</li>
<dt><strong><em>$canvas</em>-&gt;<strong>insert</strong>(<em>tagOrId, beforeThis, string</em>)</strong>

<dd>
<p>For each of the items given by <em>tagOrId</em>, if the item supports
text or coordinate, insertion then <em>string</em> is inserted into the item's
text just before the character, or coordinate, whose index is <em>beforeThis</em>.
Text items interpret <em>beforethis</em> as an index to a  character,
line and polygon items interpret it as an index to a coordinate (an x,y pair).
For lines and polygons the <em>string</em> must be a valid coordinate
sequence.
See <a href="#indices">INDICES</a> above for information about the forms allowed
for <em>beforeThis</em>.
This method returns an empty string.</p>
</dd>
</li>
<dt><strong><a name="item_itemcget"><em>$canvas</em>-&gt;<strong>itemcget</strong>(<em>tagOrId, </em><em>option</em>)</a></strong>

<dd>
<p>Returns the current value of the configuration option for the
item given by <em>tagOrId</em> whose name is <em>option</em>.
This method is similar to the <a href="../../lib/Tk/option.html">cget</a> method except that
it applies to a particular item rather than the widget as a whole.
<em>Option</em> may have any of the values accepted by the <strong>create</strong>
method when the item was created.
If <em>tagOrId</em> is a tag that refers to more than one item,
the first (lowest) such item is used.</p>
</dd>
</li>
<dt><strong><a name="item_itemconfigure"><em>$canvas</em>-&gt;<strong>itemconfigure</strong>(<em>tagOrId, </em>?<em>option</em>?, ?<em>value</em>?, ?<em>option, value, ...</em>?)</a></strong>

<dd>
<p>This method is similar to the <a href="../../lib/Tk/option.html">configure</a> method except
that it modifies item-specific options for the items given by
<em>tagOrId</em> instead of modifying options for the overall
canvas widget.
If no <em>option</em> is specified, returns a list describing all of
the available options for the first item given by <em>tagOrId</em>
(see <a href="../../lib/Tk/options.html">the Tk::options manpage</a> for
information on the format of this list).  If <em>option</em> is specified
with no <em>value</em>, then the method returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no <em>option</em> is specified).  If
one or more <em>option-value</em> pairs are specified, then the method
modifies the given widget <code>option(s)</code> to have the given <code>value(s)</code> in
each of the items given by <em>tagOrId</em>;  in
this case the method returns an empty string.
The <em>option</em>s and <em>value</em>s are the same as those permissible
in the <strong>create</strong> method when the <code>item(s)</code> were created;
see the sections describing individual item types below for details
on the legal options.</p>
</dd>
</li>
<dt><strong><a name="item_lower"><em>$canvas</em>-&gt;<strong>lower</strong>(<em>tagOrId, </em>?<em>belowThis</em>?)</a></strong>

<dd>
<p>Move all of the items given by <em>tagOrId</em> to a new position
in the display list just before the item given by <em>belowThis</em>.
If <em>tagOrId</em> refers to more than one item then all are moved
but the relative order of the moved items will not be changed.
<em>BelowThis</em> is a tag or id;  if it refers to more than one
item then the first (lowest) of these items in the display list is used
as the destination location for the moved items.
Note: this method has no effect on window items.  Window items always

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?