widget.html

来自「perl教程」· HTML 代码 · 共 854 行 · 第 1/3 页

HTML
854
字号
<?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::Widget - Base class of all 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::Widget - Base class of all 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="#description">DESCRIPTION</a></li>
	<li><a href="#caveats">CAVEATS</a></li>
	<li><a href="#keywords">KEYWORDS</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tk::Widget - Base class of all widgets</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
   <span class="keyword">package</span> <span class="variable">Tk::Whatever</span><span class="operator">;</span>
   <span class="keyword">require</span> <span class="variable">Tk::Widget</span><span class="operator">;</span>
   <span class="variable">@ISA</span> <span class="operator">=</span> <span class="string">qw(Tk::Widget)</span><span class="operator">;</span>
   <span class="variable">Construct</span> <span class="variable">Tk::Widget</span> <span class="string">'Whatever'</span><span class="operator">;</span>
</pre>
<pre>
   <span class="keyword">sub</span><span class="variable"> Tk_cmd </span><span class="operator">{</span> <span class="operator">\&amp;</span><span class="variable">Tk::whatever</span> <span class="operator">}</span>
</pre>
<p>&nbsp;&nbsp;&nbsp;<em>$widget</em>-&gt;<em>method</em>(?<em>arg, arg, ...</em>?)</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <strong>Tk::Widget</strong> is an abstract base class for all Tk widgets.</p>
<p>Generic methods available to all widgets include the methods based on core
<code>winfo</code> mechanism and are used to retrieve information about windows managed by
Tk. They can take any of a number of different forms, depending on the <em>method</em>.
The legal forms are:</p>
<dl>
<dt><strong><a name="item_appname"><em>$widget</em>-&gt;<strong>appname</strong>?(<em>newName</em>)?</a></strong>

<dd>
<p>If <em>newName</em> isn't specified, this method returns the name
of the application (the name that may be used in <strong>send</strong>
commands to communicate with the application).
If <em>newName</em> is specified, then the name of the application
is changed to <em>newName</em>.
If the given name is already in use, then a suffix of the form
``<strong> #2</strong>'' or ``<strong> #3</strong>'' is appended in order to make the name unique.
The method's result is the name actually chosen.
<em>newName</em> should not start with a capital letter.
This will interfere with <a href="../../lib/Tk/option.html">option</a> processing, since names starting with
capitals are assumed to be classes;  as a result, Tk may not
be able to find some options for the application.
If sends have been disabled by deleting the <strong>send</strong> command,
this command will reenable them and recreate the <strong>send</strong>
command.</p>
</dd>
</li>
<dt><strong><a name="item_atom"><em>$widget</em>-&gt;<strong>atom</strong>(<em>name</em>)</a></strong>

<dd>
<p>Returns a decimal string giving the integer identifier for the
atom whose name is <em>name</em>.  If no atom exists with the name
<em>name</em> then a new one is created.</p>
</dd>
</li>
<dt><strong><a name="item_atomname"><em>$widget</em>-&gt;<strong>atomname</strong>(<em>id</em>)</a></strong>

<dd>
<p>Returns the textual name for the atom whose integer identifier is
<em>id</em>.
This command is the inverse of the <em>$widget</em>-&gt;<strong>atom</strong> command.
It generates an error if no such atom exists.</p>
</dd>
</li>
<dt><strong><a name="item_bell"><em>$widget</em>-&gt;<strong>bell</strong>( ?-nice? );</a></strong>

<dd>
<p>This command rings the bell on the display for <em>$widget</em> and
returns an empty string.
The command uses the current bell-related settings for the display, which
may be modified with programs such as <strong>xset</strong>.</p>
</dd>
<dd>
<p>If <em>-nice</em>  is  not specified, this command also resets the screen saver
for the screen.  Some screen savers will ignore this, but  others  will
reset so that the screen becomes visible again.</p>
</dd>
</li>
<dt><strong><a name="item_binddump"><em>$widget</em>-&gt;<strong>bindDump</strong></a></strong>

<dd>
<p>This command returns a list of strings suitable for printing detailing
binding information for a widget.  It prints a widget's
bindtags.  For each binding tag it prints all the bindings, comprised
of the event descriptor and the callback.  Callback arguments are
printed, and <strong>Tk::Ev</strong> objects are expanded.</p>
</dd>
</li>
<dt><strong><a name="item_busy"><em>$widget</em>-&gt;<strong>Busy</strong>?(?-recurse =&gt; 1?<em>-option =</em> value&gt;?)?</a></strong>

<dd>
<p>This method <strong>configure</strong>s a <strong>-cursor</strong> option for <em>$widget</em> and
(if <strong>-recurse =</strong> 1&gt; is specified) all its descendants. The cursor to
be set may be passed as <strong>-cursor</strong>&nbsp;= <em>cursor</em>&gt; or defaults to 'watch'.
Additional <strong>configure</strong> options are applied to <em>$widget</em> only.
It also adds a special tag <strong>'Busy'</strong> to the <strong>bindtags</strong> of the widgets so
configured so that  <strong>KeyPress</strong>, <strong>KeyRelease</strong>, <strong>ButtonPress</strong> and
<strong>ButtonRelease</strong> events are ignored (with press events generating a call to
<strong>bell</strong>). It then acquires a local <strong>grab</strong> for <em>$widget</em>.
The state of the widgets and the grab is restored by a call to
<em>$widget</em>-&gt;<strong>Unbusy</strong>.</p>
</dd>
</li>
<dt><strong><a name="item_caret"><em>$widget</em>-&gt;<strong>caret</strong>( <em>?-x x?, ?-y y?, ?-height height?</em> );</a></strong>

<dd>
<p>Sets and queries the caret location for the display of the specified
Tk window window.  The caret is the per-display cursor location used
for indicating global focus (e.g. to comply with Microsoft
Accessibility guidelines), as well as for location of the
over-the-spot XIM (X Input Methods) or Windows IME windows. If no
options are specified, the last values used for setting the caret are
return in option-value pair format.  -x and -y represent
window-relative coordinates, and -height is the height of the current
cursor location, or the height of the specified window if none is
given.</p>
</dd>
</li>
<dt><strong><a name="item_cells"><em>$widget</em>-&gt;<strong>cells</strong></a></strong>

<dd>
<p>Returns a decimal string giving the number of cells in the
color map for <em>$widget</em>.</p>
</dd>
</li>
<dt><strong><a name="item_children"><em>$widget</em>-&gt;<strong>children</strong></a></strong>

<dd>
<p><em>$widget-</em>&gt;<strong>children</strong>
Returns a list containing all the children
of $widget.  The list is in stacking order, with the lowest
window first.  Top-level windows are returned as children
of their logical parents.</p>
</dd>
</li>
<dt><strong><a name="item_class"><em>$widget</em>-&gt;<strong>class</strong></a></strong>

<dd>
<p>Returns the class name for <em>$widget</em>.</p>
</dd>
</li>
<dt><strong><a name="item_colormapfull"><em>$widget</em>-&gt;<strong>colormapfull</strong></a></strong>

<dd>
<p>Returns 1 if the colormap for <em>$widget</em> is known to be full, 0
otherwise.  The colormap for a window is ``known'' to be full if the last
attempt to allocate a new color on that window failed and this
application hasn't freed any colors in the colormap since the
failed allocation.</p>
</dd>
</li>
<dt><strong><a name="item_configspecs"><em>$widget</em>-&gt;<strong>ConfigSpecs</strong></a></strong>

<dd>
<p>Used to perform delegated option configuration for a mega-widget.
Returns, in Tk::Derived::ConfigSpecs notation (see <a href="../../lib/Tk/ConfigSpecs.html">the Tk::ConfigSpecs manpage</a>),
all possible options for a widget. For example,</p>
</dd>
<dd>
<pre>
 <span class="variable">$s</span> <span class="operator">=</span> <span class="variable">$self</span><span class="operator">-&gt;</span><span class="variable">Scale</span><span class="operator">;</span>
 <span class="variable">$self</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span>
     <span class="variable">$s</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">,</span>
     <span class="operator">....</span> <span class="variable">more</span> <span class="variable">ConfigSpecs</span> <span class="variable">specifications</span>
 <span class="operator">);</span>
</pre>
</dd>
<dd>
<p>returns a hash of all Tk::Scale options, delegated to $s - e.g. some
representative examples:</p>
</dd>
<dd>
<pre>
 -bigincrement =&gt; [$s, bigIncrement, BigIncrement, 0, 0]
 -digits       =&gt; [$s, digits, Digits, 0, 0]
 -sliderlength =&gt; [$s, sliderLength, SliderLength, 10m, 30]
 -troughcolor  =&gt; [$s, troughColor, Background, #c3c3c3, #c3c3c3]</pre>
</dd>
<dd>
<p>This provides an easy means of populating a mega-widget's ConfigSpecs
with initializers.</p>
</dd>
</li>
<dt><strong><a name="item_containing"><em>$widget</em>-&gt;<strong>containing</strong>(<em>rootX,rootY</em>)</a></strong>

<dd>
<p>Returns the window containing the point given
by <em>rootX</em> and <em>rootY</em>.
<em>RootX</em> and <em>rootY</em> are specified in screen units (i.e.
any form acceptable to <strong>Tk_GetPixels</strong>) in the coordinate
system of the root window (if a virtual-root window manager is in
use then the coordinate system of the virtual root window is used).
If no window in this application contains the point then an empty
string is returned.
In selecting the containing window, children are given higher priority
than parents and among siblings the highest one in the stacking order is
chosen.</p>
</dd>
</li>
<dt><strong><a name="item_depth"><em>$widget</em>-&gt;<strong>depth</strong></a></strong>

<dd>
<p>Returns a decimal string giving the depth of <em>$widget</em> (number
of bits per pixel).</p>
</dd>
</li>
<dt><strong><a name="item_destroy"><em>$widget</em>-&gt;<strong>destroy</strong></a></strong>

<dd>
<p>This command deletes the window related to
<em>$widget</em>, plus all its descendants.
If all the <strong>MainWindows</strong> are deleted then the entire application
will be destroyed.</p>
</dd>
<dd>
<p>The perl object <em>$widget</em> continues to exist while references
to it still exist, e.g. until variable goes out of scope.
However any attempt to use Tk methods on the object will fail.
<strong>Exists</strong>(<em>$widget</em>) will return false on such objects.</p>
</dd>
<dd>
<p>Note however that while a window exists for <em>$widget</em> the
perl object is maintained (due to &quot;references&quot; in perl/Tk internals)
even though original variables may have gone out of scope.
(Normally this is intuitive.)</p>
</dd>
</li>
<dt><strong><a name="item_exists"><strong>Exists</strong>(<em>$widget</em>)</a></strong>

<dd>
<p>Returns 1 if there exists a window for <em>$widget</em>, 0 if no such
window exists.</p>
</dd>
</li>
<dt><strong><a name="item_font"><em>$widget</em>-&gt;<strong>font</strong>(<em>option</em>?, <em>arg, arg, ...</em>?)</a></strong>

<dd>
<p>Create and inspect fonts. See <a href="../../lib/Tk/Font.html">the Tk::Font manpage</a> for further details.</p>
</dd>
</li>
<dt><strong><a name="item_fpixels"><em>$widget</em>-&gt;<strong>fpixels</strong>(<em>number</em>)</a></strong>

<dd>
<p>Returns a floating-point value giving the number of pixels
in <em>$widget</em> corresponding to the distance given by <em>number</em>.
<em>Number</em> may be specified in any of the forms acceptable
to <strong>Tk_GetScreenMM</strong>, such as ``2.0c'' or ``1i''.
The return value may be fractional;  for an integer value, use
<em>$widget</em>-&gt;<strong>pixels</strong>.</p>
</dd>

⌨️ 快捷键说明

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