scale.html
来自「perl教程」· HTML 代码 · 共 445 行 · 第 1/2 页
HTML
445 行
This value may be either less than or greater than the <strong>from</strong> option.</p>
</dd>
</li>
<dt><strong><a name="item_name_3a_variable">Name: <strong>variable</strong></a></strong>
<dt><strong><a name="item_class_3a_variable">Class: <strong>Variable</strong></a></strong>
<dt><strong><a name="item_switch_3a__2dvariable">Switch: <strong>-variable</strong></a></strong>
<dd>
<p>Specifies the name of a global variable to link to the scale. Whenever the
value of the variable changes, the scale will update to reflect this
value.
Whenever the scale is manipulated interactively, the variable
will be modified to reflect the scale's new value.</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 the desired narrow dimension of the trough in screen units
(i.e. any of the forms acceptable to <strong>Tk_GetPixels</strong>).
For vertical scales this is the trough's width; for horizontal scales
this is the trough's height.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <strong>Scale</strong> method creates a new window (given by the
$widget argument) and makes it into a scale widget.
Additional
options, described above, may be specified on the command line
or in the option database
to configure aspects of the scale such as its colors, orientation,
and relief. The <strong>scale</strong> command returns its
$widget argument. At the time this command is invoked,
there must not exist a window named $widget, but
$widget's parent must exist.</p>
<p>A scale is a widget that displays a rectangular <em>trough</em> and a
small <em>slider</em>. The trough corresponds to a range
of real values (determined by the <strong>from</strong>, <strong>to</strong>, and
<strong>resolution</strong> options),
and the position of the slider selects a particular real value.
The slider's position (and hence the scale's value) may be adjusted
with the mouse or keyboard as described in
the <a href="#bindings">BINDINGS</a> section below. Whenever the scale's value is changed, a Tcl
command is invoked (using the <strong>command</strong> option) to notify
other interested widgets of the change.
In addition, the value
of the scale can be linked to a Tcl variable (using the <strong>variable</strong>
option), so that changes in either are reflected in the other.</p>
<p>Three annotations may be displayed in a scale widget: a label
appearing at the top right of the widget (top left for horizontal
scales), a number displayed just to the left of the slider
(just above the slider for horizontal scales), and a collection
of numerical tick marks just to the left of the current value
(just below the trough for horizontal scales). Each of these three
annotations may be enabled or disabled using the
configuration options.</p>
<p>
</p>
<hr />
<h1><a name="widget_methods">WIDGET METHODS</a></h1>
<p>The <strong>Scale</strong> method creates a widget object.
This object supports the <strong>configure</strong> and <strong>cget</strong> methods
described in <a href="../../lib/Tk/options.html">the Tk::options manpage</a> which can be used to enquire and
modify the options described above.
The widget also inherits all the methods provided by the generic
<a href="../../lib/Tk/Widget.html">Tk::Widget</a> class.</p>
<p>The following additional methods are available for scale widgets:</p>
<dl>
<dt><strong><a name="item_coords"><em>$scale</em>-><strong>coords</strong>(?<em>value</em>?)</a></strong>
<dd>
<p>Returns a list whose elements are the x and y coordinates of
the point along the centerline of the trough that corresponds
to <em>value</em>.
If <em>value</em> is omitted then the scale's current value is used.</p>
</dd>
</li>
<dt><strong><a name="item_get"><em>$scale</em>-><strong>get</strong>(?<em>x, y</em>?)</a></strong>
<dd>
<p>If <em>x</em> and <em>y</em> are omitted, returns the current value
of the scale. If <em>x</em> and <em>y</em> are specified, they give
pixel coordinates within the widget; the command returns
the scale value corresponding to the given pixel.
Only one of <em>x</em> or <em>y</em> is used: for horizontal scales
<em>y</em> is ignored, and for vertical scales <em>x</em> is ignored.</p>
</dd>
</li>
<dt><strong><a name="item_identify"><em>$scale</em>-><strong>identify</strong>(<em>x, y</em>)</a></strong>
<dd>
<p>Returns a string indicating what part of the scale lies under
the coordinates given by <em>x</em> and <em>y</em>.
A return value of <strong>slider</strong> means that the point is over
the slider; <strong>trough1</strong> means that the point is over the
portion of the slider above or to the left of the slider;
and <strong>trough2</strong> means that the point is over the portion
of the slider below or to the right of the slider.
If the point isn't over one of these elements, an empty string
is returned.</p>
</dd>
</li>
<dt><strong><a name="item_set"><em>$scale</em>-><strong>set</strong>(<em>value</em>)</a></strong>
<dd>
<p>This command is invoked to change the current value of the scale,
and hence the position at which the slider is displayed. <em>Value</em>
gives the new value for the scale.
The command has no effect if the scale is disabled.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="bindings">BINDINGS</a></h1>
<p>Tk automatically creates class bindings for scales that give them
the following default behavior.
Where the behavior is different for vertical and horizontal scales,
the horizontal behavior is described in parentheses.</p>
<dl>
<dt><strong><a name="item__5b1_5d">[1]</a></strong>
<dd>
<p>If button 1 is pressed in the trough, the scale's value will
be incremented or decremented by the value of the <strong>resolution</strong>
option so that the slider moves in the direction of the cursor.
If the button is held down, the action auto-repeats.</p>
</dd>
</li>
<dt><strong><a name="item__5b2_5d">[2]</a></strong>
<dd>
<p>If button 1 is pressed over the slider, the slider can be dragged
with the mouse.</p>
</dd>
</li>
<dt><strong><a name="item__5b3_5d">[3]</a></strong>
<dd>
<p>If button 1 is pressed in the trough with the Control key down,
the slider moves all the way to the end of its range, in the
direction towards the mouse cursor.</p>
</dd>
</li>
<dt><strong><a name="item__5b4_5d">[4]</a></strong>
<dd>
<p>If button 2 is pressed, the scale's value is set to the mouse
position. If the mouse is dragged with button 2 down, the scale's
value changes with the drag.</p>
</dd>
</li>
<dt><strong><a name="item__5b5_5d">[5]</a></strong>
<dd>
<p>The Up and Left keys move the slider up (left) by the value
of the <strong>resolution</strong> option.</p>
</dd>
</li>
<dt><strong><a name="item__5b6_5d">[6]</a></strong>
<dd>
<p>The Down and Right keys move the slider down (right) by the value
of the <strong>resolution</strong> option.</p>
</dd>
</li>
<dt><strong><a name="item__5b7_5d">[7]</a></strong>
<dd>
<p>Control-Up and Control-Left move the slider up (left) by the
value of the <strong>bigIncrement</strong> option.</p>
</dd>
</li>
<dt><strong><a name="item__5b8_5d">[8]</a></strong>
<dd>
<p>Control-Down and Control-Right move the slider down (right) by the
value of the <strong>bigIncrement</strong> option.</p>
</dd>
</li>
<dt><strong><a name="item__5b9_5d">[9]</a></strong>
<dd>
<p>Home moves the slider to the top (left) end of its range.</p>
</dd>
</li>
<dt><strong><a name="item__5b10_5d">[10]</a></strong>
<dd>
<p>End moves the slider to the bottom (right) end of its range.</p>
</dd>
<dd>
<p>If the scale is disabled using the <strong>state</strong> option then
none of the above bindings have any effect.</p>
</dd>
<dd>
<p>The behavior of scales can be changed by defining new bindings for
individual widgets or by redefining the class bindings.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="keywords">KEYWORDS</a></h1>
<p>scale, slider, trough, widget</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?