canvas.html

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

HTML
1,385
字号
<?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::Canvas - Create and manipulate Canvas widgets</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::Canvas - Create and manipulate Canvas widgets</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="#standard_options">STANDARD OPTIONS</a></li>
	<li><a href="#widgetspecific_options">WIDGET-SPECIFIC OPTIONS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#display_list">DISPLAY LIST</a></li>
	<li><a href="#item_ids_and_tags">ITEM IDS AND TAGS</a></li>
	<li><a href="#coordinates">COORDINATES</a></li>
	<li><a href="#transformations">TRANSFORMATIONS</a></li>
	<li><a href="#indices">INDICES</a></li>
	<li><a href="#dash_patterns">DASH PATTERNS</a></li>
	<li><a href="#widget_methods">WIDGET METHODS</a></li>
	<li><a href="#overview_of_item_types">OVERVIEW OF ITEM TYPES</a></li>
	<li><a href="#arc_items">ARC ITEMS</a></li>
	<li><a href="#bitmap_items">BITMAP ITEMS</a></li>
	<li><a href="#grid_items">GRID ITEMS</a></li>
	<li><a href="#image_items">IMAGE ITEMS</a></li>
	<li><a href="#line_items">LINE ITEMS</a></li>
	<li><a href="#oval_items">OVAL ITEMS</a></li>
	<li><a href="#polygon_items">POLYGON ITEMS</a></li>
	<li><a href="#rectangle_items">RECTANGLE ITEMS</a></li>
	<li><a href="#text_items">TEXT ITEMS</a></li>
	<li><a href="#window_items">WINDOW ITEMS</a></li>
	<li><a href="#applicationdefined_item_types">APPLICATION-DEFINED ITEM TYPES</a></li>
	<li><a href="#bindings">BINDINGS</a></li>
	<li><a href="#perl_tk_methods">Perl/Tk Methods</a></li>
	<li><a href="#credits">CREDITS</a></li>
	<li><a href="#keywords">KEYWORDS</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tk::Canvas - Create and manipulate Canvas widgets</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p><em>$canvas</em> = <em>$parent</em>-&gt;<strong>Canvas</strong>(?<em>options</em>?);</p>
<p>
</p>
<hr />
<h1><a name="standard_options">STANDARD OPTIONS</a></h1>
<p><table cellspacing="0" cellpadding="0"><tr><td><strong>-background</strong><td><strong>-highlightthickness</strong><td><strong>-insertwidth</strong><td><strong>-state</strong>
<tr><td><strong>-borderwidth</strong><td><strong>-insertbackground</strong><td><strong>-relief</strong><td><strong>-tile</strong>
<tr><td><strong>-cursor</strong><td><strong>-insertborderwidth</strong><td><strong>-selectbackground</strong><td><strong>-takefocus</strong>
<tr><td><strong>-highlightbackground</strong><td><strong>-insertofftime</strong><td><strong>-selectborderwidth</strong><td><strong>-xscrollcommand</strong>
<tr><td><strong>-highlightcolor</strong><td><strong>-insertontime</strong><td><strong>-selectforeground</strong><td><strong>-yscrollcommand</strong></table></p>
<p>
</p>
<hr />
<h1><a name="widgetspecific_options">WIDGET-SPECIFIC OPTIONS</a></h1>
<dl>
<dt><strong><a name="item_name_3a_closeenough">Name:	<strong>closeEnough</strong></a></strong>

<dt><strong><a name="item_class_3a_closeenough">Class:	<strong>CloseEnough</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dcloseenough">Switch:	<strong>-closeenough</strong></a></strong>

<dd>
<p>Specifies a floating-point value indicating how close the mouse cursor
must be to an item before it is considered to be ``inside'' the item.
Defaults to 1.0.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_confine">Name:	<strong>confine</strong></a></strong>

<dt><strong><a name="item_class_3a_confine">Class:	<strong>Confine</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dconfine">Switch:	<strong>-confine</strong></a></strong>

<dd>
<p>Specifies a boolean value that indicates whether or not it should be
allowable to set the canvas's view outside the region defined by the
<strong>scrollRegion</strong> argument.
Defaults to true, which means that the view will
be constrained within the scroll region.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_height">Name:	<strong>height</strong></a></strong>

<dt><strong><a name="item_class_3a_height">Class:	<strong>Height</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dheight">Switch:	<strong>-height</strong></a></strong>

<dd>
<p>Specifies a desired window height that the canvas widget should request from
its geometry manager.  The value may be specified in any
of the forms described in the <a href="#coordinates">COORDINATES</a> section below.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_scrollregion">Name:	<strong>scrollRegion</strong></a></strong>

<dt><strong><a name="item_class_3a_scrollregion">Class:	<strong>ScrollRegion</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dscrollregion">Switch:	<strong>-scrollregion</strong></a></strong>

<dd>
<p>Specifies a list with four coordinates describing the left, top, right, and
bottom coordinates of a rectangular region.
This region is used for scrolling purposes and is considered to be
the boundary of the information in the canvas.
Each of the coordinates may be specified
in any of the forms given in the <a href="#coordinates">COORDINATES</a> section below.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_state">Name:	<strong>state</strong></a></strong>

<dt><strong><a name="item_class_3a_state">Class:	<strong>State</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dstate">Switch:	<strong>-state</strong></a></strong>

<dd>
<p>Modifies the default state of the canvas where <em>state</em> may be set to one of:
normal, disabled, or hidden. Individual canvas objects all have their own
state option, which overrides the default state. Many options can take
separate specifications such that the appearance of the item can be different
in different situations. The options that start with &quot;active&quot; control the
appearence when the mouse pointer is over it, while the option starting
with &quot;disabled&quot; controls the appearence when the state is disabled.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_width">Name:	<strong>width</strong></a></strong>

<dt><strong><a name="item_class_3a_width">Class:	<strong>width</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dwidth">Switch:	<strong>-width</strong></a></strong>

<dd>
<p>Specifies a desired window width that the canvas widget should request from
its geometry manager.  The value may be specified in any
of the forms described in the <a href="#coordinates">COORDINATES</a> section below.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_xscrollincrement">Name:	<strong>xScrollIncrement</strong></a></strong>

<dt><strong><a name="item_class_3a_scrollincrement">Class:	<strong>ScrollIncrement</strong></a></strong>

<dt><strong><a name="item_switch_3a__2dxscrollincrement">Switch:	<strong>-xscrollincrement</strong></a></strong>

<dd>
<p>Specifies an increment for horizontal scrolling, in any of the usual forms
permitted for screen distances.  If the value of this option is greater
than zero, the horizontal view in the window will be constrained so that
the canvas x coordinate at the left edge of the window is always an even
multiple of <strong>xScrollIncrement</strong>;  furthermore, the units for scrolling
(e.g., the change in view when the left and right arrows of a scrollbar
are selected) will also be <strong>xScrollIncrement</strong>.  If the value of
this option is less than or equal to zero, then horizontal scrolling
is unconstrained.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_yscrollincrement">Name:	<strong>yScrollIncrement</strong></a></strong>

<dt><strong>Class:	<strong>ScrollIncrement</strong></strong>

<dt><strong><a name="item_switch_3a__2dyscrollincrement">Switch:	<strong>-yscrollincrement</strong></a></strong>

<dd>
<p>Specifies an increment for vertical scrolling, in any of the usual forms
permitted for screen distances.  If the value of this option is greater
than zero, the vertical view in the window will be constrained so that
the canvas y coordinate at the top edge of the window is always an even
multiple of <strong>yScrollIncrement</strong>;  furthermore, the units for scrolling
(e.g., the change in view when the top and bottom arrows of a scrollbar
are selected) will also be <strong>yScrollIncrement</strong>.  If the value of
this option is less than or equal to zero, then vertical scrolling
is unconstrained.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <strong>Canvas</strong> method creates a new window (given
by the $canvas argument) and makes it into a canvas widget.
Additional options, described above, may be specified on the
command line or in the option database
to configure aspects of the canvas such as its colors and 3-D relief.
The <strong>canvas</strong> command returns its
$canvas argument.  At the time this command is invoked,
there must not exist a window named $canvas, but
$canvas's parent must exist.</p>
<p>Canvas widgets implement structured graphics.
A canvas displays any number of <em>items</em>, which may be things like
rectangles, circles, lines, and text.
Items may be manipulated (e.g. moved or re-colored) and
<a href="../../lib/Tk/callbacks.html">callbacks</a> may
be associated with items in much the same way that the <a href="../../lib/Tk/bind.html">bind</a>
method allows callbacks to be bound to widgets.  For example,
a particular callback may be associated with the <strong>&lt;Button-1&gt;</strong> event
so that the callback is invoked whenever button 1 is pressed with
the mouse cursor over an item.
This means that items in a canvas can have behaviors defined by
the Callbacks bound to them.</p>
<p>
</p>
<hr />
<h1><a name="display_list">DISPLAY LIST</a></h1>
<p>The items in a canvas are ordered for purposes of display,
with the first item in the display list being displayed
first, followed by the next item in the list, and so on.
Items later in the display list obscure those that are
earlier in the display list and are sometimes referred to
as being <em>``on top''</em> of earlier items.
When a new item is created it is placed at the end of the
display list, on top of everything else.
Widget methods may be used to re-arrange the order of the
display list.</p>
<p>Window items are an exception to the above rules.  The underlying
window systems require them always to be drawn on top of other items.
In addition, the stacking order of window items
is not affected by any of the canvas methods; you must use
the <a href="../../lib/Tk/Widget.html">raise</a> and <a href="../../lib/Tk/Widget.html">lower</a> Tk widget methods instead.</p>
<p>
</p>
<hr />
<h1><a name="item_ids_and_tags">ITEM IDS AND TAGS</a></h1>
<p>Items in a canvas widget may be named in either of two ways:
by id or by tag.
Each item has a unique identifying number which is assigned to
that item when it is created.  The id of an item never changes
and id numbers are never re-used within the lifetime of a
canvas widget.</p>
<p>Each item may also have any number of <em>tags</em> associated
with it.  A tag is just a string of characters, and it may
take any form except that of an integer.
For example, ``x123'' is OK but ``123'' isn't.
The same tag may be associated with many different items.
This is commonly done to group items in various interesting
ways;  for example, all selected items might be given the
tag ``selected''.</p>
<p>The tag <strong>all</strong> is implicitly associated with every item
in the canvas;  it may be used to invoke operations on
all the items in the canvas.</p>
<p>The tag <strong>current</strong> is managed automatically by Tk;
it applies to the <em>current item</em>, which is the
topmost item whose drawn area covers the position of
the mouse cursor.
If the mouse is not in the canvas widget or is not over
an item, then no item has the <strong>current</strong> tag.</p>
<p>When specifying items in canvas methods, if the
specifier is an integer then it is assumed to refer to
the single item with that id.
If the specifier is not an integer, then it is assumed to
refer to all of the items in the canvas that have a tag
matching the specifier.
The symbol <em>tagOrId</em> is used below to indicate that
an argument specifies either an id that selects a single

⌨️ 快捷键说明

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