scrollbar.html

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

HTML
523 行
字号
<dt><strong><a name="item_set"><em>$scrollbar</em>-&gt;<strong>set</strong>(<em>first, last</em>)</a></strong>

<dd>
<p>This command is invoked by the scrollbar's associated widget to
tell the scrollbar about the current view in the widget.
The command takes two arguments, each of which is a real fraction
between 0 and 1.
The fractions describe the range of the document that is visible in
the associated widget.
For example, if <em>first</em> is 0.2 and <em>last</em> is 0.4, it means
that the first part of the document visible in the window is 20%
of the way through the document, and the last visible part is 40%
of the way through.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="scrolling_commands">SCROLLING COMMANDS</a></h1>
<p>When the user interacts with the scrollbar, for example by dragging
the slider, the scrollbar notifies the associated widget that it
must change its view.
The scrollbar makes the notification by evaluating a callback
specified as the scrollbar's <strong>-command</strong> option.
The callback may take several forms.
In each case, the intial arguments passed are those
specified in the <strong>-command</strong> callback itself,
which usually has a form like [<strong>yview</strong> =&gt; <em>$widget</em>].
(Which will invoke <em>$widget</em>-&gt;<strong>yview</strong>(...) where
the ... part is as below. See <a href="../../lib/Tk/callbacks.html">the Tk::callbacks manpage</a> for details.)
The callback is passed additional arguments as follows:</p>
<dl>
<dt><strong><a name="item_moveto_2cfraction"><strong>moveto</strong>,<em>fraction</em></a></strong>

<dd>
<p><em>Fraction</em> is a real number between 0 and 1.
The widget should adjust its view so that the point given
by <em>fraction</em> appears at the beginning of the widget.
If <em>fraction</em> is 0 it refers to the beginning of the
document.  1.0 refers to the end of the document, 0.333
refers to a point one-third of the way through the document,
and so on.</p>
</dd>
</li>
<dt><strong><a name="item_scroll_2cnumber_2cunits"><strong>scroll,</strong><em>number,</em><strong>units</strong></a></strong>

<dd>
<p>The widget should adjust its view by <em>number</em> units.
The units are defined in whatever way makes sense for the widget,
such as characters or lines in a text widget.
<em>Number</em> is either 1, which means one unit should scroll off
the top or left of the window, or -1, which means that one unit
should scroll off the bottom or right of the window.</p>
</dd>
</li>
<dt><strong><a name="item_scroll_2cnumber_2cpage"><strong>scroll</strong>,<em>number</em>,<strong>page</strong></a></strong>

<dd>
<p>The widget should adjust its view by <em>number</em> pages.
It is up to the widget to define the meaning of a page;  typically
it is slightly less than what fits in the window, so that there
is a slight overlap between the old and new views.
<em>Number</em> is either 1, which means the next page should
become visible, or -1, which means that the previous page should
become visible.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="old_command_syntax">OLD COMMAND SYNTAX</a></h1>
<p>In versions of Tk before 4.0, the <strong>set</strong> and <strong>get</strong> widget
commands used a different form.
This form is still supported for backward compatibility, but it
is deprecated.
In the old command syntax, the <strong>set</strong> method has the
following form:</p>
<dl>
<dt><strong><em>$scrollbar</em>-&gt;<strong>set</strong>(<em>totalUnits, windowUnits, firstUnit, lastUnit</em>)</strong>

<dd>
<p>In this form the arguments are all integers.
<em>TotalUnits</em> gives the total size of the object being displayed in the
associated widget.  The meaning of one unit depends on the associated
widget;  for example, in a text editor widget units might
correspond to lines of
text.  <em>WindowUnits</em> indicates the total number of units that
can fit in the associated window at one time.  <em>FirstUnit</em>
and <em>lastUnit</em> give the indices of the first and last units
currently visible in the associated window (zero corresponds to the
first unit of the object).</p>
</dd>
</li>
</dl>
<p>Under the old syntax the <strong>get</strong> method returns a list
of four integers, consisting of the <em>totalUnits</em>, <em>windowUnits</em>,
<em>firstUnit</em>, and <em>lastUnit</em> values from the last <strong>set</strong>
method.</p>
<p>The callbacks generated by scrollbars also have a different form
when the old syntax is being used, the callback is passed a single argument:</p>
<dl>
<dt><strong><a name="item_unit"><em>unit</em></a></strong>

<dd>
<p><em>Unit</em> is an integer that indicates what should appear at
the top or left of the associated widget's window.
It has the same meaning as the <em>firstUnit</em> and <em>lastUnit</em>
arguments to the <strong>set</strong> method.</p>
</dd>
</li>
</dl>
<p>The most recent <strong>set</strong> method determines whether or not
to use the old syntax.
If it is given two real arguments then the new syntax will be
used in the future, and if it is given four integer arguments then
the old syntax will be used.</p>
<p>
</p>
<hr />
<h1><a name="bindings">BINDINGS</a></h1>
<p>Tk automatically creates class bindings for scrollbars that give them
the following default behavior.
If the behavior is different for vertical and horizontal scrollbars,
the horizontal behavior is described in parentheses.</p>
<dl>
<dt><strong><a name="item__5b1_5d">[1]</a></strong>

<dd>
<p>Pressing button 1 over <strong>arrow1</strong> causes the view in the
associated widget to shift up (left) by one unit so that the
document appears to move down (right) one unit.
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>Pressing button 1 over <strong>trough1</strong> causes the view in the
associated widget to shift up (left) by one screenful so that the
document appears to move down (right) one screenful.
If the button is held down, the action auto-repeats.</p>
</dd>
</li>
<dt><strong><a name="item__5b3_5d">[3]</a></strong>

<dd>
<p>Pressing button 1 over the slider and dragging causes the view
to drag with the slider.
If the <strong>jump</strong> option is true, then the view doesn't drag along
with the slider;  it changes only when the mouse button is released.</p>
</dd>
</li>
<dt><strong><a name="item__5b4_5d">[4]</a></strong>

<dd>
<p>Pressing button 1 over <strong>trough2</strong> causes the view in the
associated widget to shift down (right) by one screenful so that the
document appears to move up (left) one screenful.
If the button is held down, the action auto-repeats.</p>
</dd>
</li>
<dt><strong><a name="item__5b5_5d">[5]</a></strong>

<dd>
<p>Pressing button 1 over <strong>arrow2</strong> causes the view in the
associated widget to shift down (right) by one unit so that the
document appears to move up (left) one unit.
If the button is held down, the action auto-repeats.</p>
</dd>
</li>
<dt><strong><a name="item__5b6_5d">[6]</a></strong>

<dd>
<p>If button 2 is pressed over the trough or the slider, it sets
the view to correspond to the mouse position;  dragging the
mouse with button 2 down causes the view to drag with the mouse.
If button 2 is pressed over one of the arrows, it causes the
same behavior as pressing button 1.</p>
</dd>
</li>
<dt><strong><a name="item__5b7_5d">[7]</a></strong>

<dd>
<p>If button 1 is pressed with the Control key down, then if the
mouse is over <strong>arrow1</strong> or <strong>trough1</strong> the view changes
to the very top (left) of the document;  if the mouse is over
<strong>arrow2</strong> or <strong>trough2</strong> the view changes
to the very bottom (right) of the document;  if the mouse is
anywhere else then the button press has no effect.</p>
</dd>
</li>
<dt><strong><a name="item__5b8_5d">[8]</a></strong>

<dd>
<p>In vertical scrollbars the Up and Down keys have the same behavior
as mouse clicks over <strong>arrow1</strong> and <strong>arrow2</strong>, respectively.
In horizontal scrollbars these keys have no effect.</p>
</dd>
</li>
<dt><strong><a name="item__5b9_5d">[9]</a></strong>

<dd>
<p>In vertical scrollbars Control-Up and Control-Down have the same
behavior as mouse clicks over <strong>trough1</strong> and <strong>trough2</strong>, respectively.
In horizontal scrollbars these keys have no effect.</p>
</dd>
</li>
<dt><strong><a name="item__5b10_5d">[10]</a></strong>

<dd>
<p>In horizontal scrollbars the Up and Down keys have the same behavior
as mouse clicks over <strong>arrow1</strong> and <strong>arrow2</strong>, respectively.
In vertical scrollbars these keys have no effect.</p>
</dd>
</li>
<dt><strong><a name="item__5b11_5d">[11]</a></strong>

<dd>
<p>In horizontal scrollbars Control-Up and Control-Down have the same
behavior as mouse clicks over <strong>trough1</strong> and <strong>trough2</strong>, respectively.
In vertical scrollbars these keys have no effect.</p>
</dd>
</li>
<dt><strong><a name="item__5b12_5d">[12]</a></strong>

<dd>
<p>The Prior and Next keys have the same behavior
as mouse clicks over <strong>trough1</strong> and <strong>trough2</strong>, respectively.</p>
</dd>
</li>
<dt><strong><a name="item__5b13_5d">[13]</a></strong>

<dd>
<p>The Home key adjusts the view to the top (left edge) of the document.</p>
</dd>
</li>
<dt><strong><a name="item__5b14_5d">[14]</a></strong>

<dd>
<p>The End key adjusts the view to the bottom (right edge) of the document.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Tk/callbacks.html">Tk::callbacks</a>
<a href="../../lib/Tk/Scrolled.html">Tk::Scrolled</a></p>
<p>
</p>
<hr />
<h1><a name="keywords">KEYWORDS</a></h1>
<p>scrollbar, widget</p>

</body>

</html>

⌨️ 快捷键说明

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