projman/hlp/en/tk/scale.htm
2015-10-19 14:27:31 +04:00

335 lines
17 KiB
HTML

<HTML><HEAD><TITLE>Tk Built-In Commands - scale manual page</TITLE></HEAD><BODY>
<DL>
<DD><A HREF="scale.htm#M2" NAME="L964">NAME</A>
<DL><DD>scale - Create and manipulate scale widgets</DL>
<DD><A HREF="scale.htm#M3" NAME="L965">SYNOPSIS</A>
<DL>
<DD><B>scale</B> <I>pathName </I>?<I>options</I>?
</DL>
<DD><A HREF="scale.htm#M4" NAME="L966">STANDARD OPTIONS</A>
<DL>
<DD><A HREF="options.htm#M-activebackground">-activebackground, activeBackground, Foreground</A>
<DD><A HREF="options.htm#M-background">-background or -bg, background, Background</A>
<DD><A HREF="options.htm#M-borderwidth">-borderwidth or -bd, borderWidth, BorderWidth</A>
<DD><A HREF="options.htm#M-cursor">-cursor, cursor, Cursor</A>
<DD><A HREF="options.htm#M-font">-font, font, Font</A>
<DD><A HREF="options.htm#M-foreground">-foreground or -fg, foreground, Foreground</A>
<DD><A HREF="options.htm#M-highlightbackground">-highlightbackground, highlightBackground, HighlightBackground</A>
<DD><A HREF="options.htm#M-highlightcolor">-highlightcolor, highlightColor, HighlightColor</A>
<DD><A HREF="options.htm#M-highlightthickness">-highlightthickness, highlightThickness, HighlightThickness</A>
<DD><A HREF="options.htm#M-orient">-orient, orient, Orient</A>
<DD><A HREF="options.htm#M-relief">-relief, relief, Relief</A>
<DD><A HREF="options.htm#M-repeatdelay">-repeatdelay, repeatDelay, RepeatDelay</A>
<DD><A HREF="options.htm#M-repeatinterval">-repeatinterval, repeatInterval, RepeatInterval</A>
<DD><A HREF="options.htm#M-takefocus">-takefocus, takeFocus, TakeFocus</A>
<DD><A HREF="options.htm#M-troughcolor">-troughcolor, troughColor, Background</A>
</DL>
<DD><A HREF="scale.htm#M5" NAME="L967">WIDGET-SPECIFIC OPTIONS</A>
<DL>
<DD><A HREF="scale.htm#M6" NAME="L968">-bigincrement, bigIncrement, BigIncrement</A>
<DD><A HREF="scale.htm#M7" NAME="L969">-command, command, Command</A>
<DD><A HREF="scale.htm#M8" NAME="L970">-digits, digits, Digits</A>
<DD><A HREF="scale.htm#M9" NAME="L971">-from, from, From</A>
<DD><A HREF="scale.htm#M10" NAME="L972">-label, label, Label</A>
<DD><A HREF="scale.htm#M11" NAME="L973">-length, length, Length</A>
<DD><A HREF="scale.htm#M12" NAME="L974">-resolution, resolution, Resolution</A>
<DD><A HREF="scale.htm#M13" NAME="L975">-showvalue, showValue, ShowValue</A>
<DD><A HREF="scale.htm#M14" NAME="L976">-sliderlength, sliderLength, SliderLength</A>
<DD><A HREF="scale.htm#M15" NAME="L977">-sliderrelief, sliderRelief, SliderRelief</A>
<DD><A HREF="scale.htm#M16" NAME="L978">-state, state, State</A>
<DD><A HREF="scale.htm#M17" NAME="L979">-tickinterval, tickInterval, TickInterval</A>
<DD><A HREF="scale.htm#M18" NAME="L980">-to, to, To</A>
<DD><A HREF="scale.htm#M19" NAME="L981">-variable, variable, Variable</A>
<DD><A HREF="scale.htm#M20" NAME="L982">-width, width, Width</A>
</DL>
<DD><A HREF="scale.htm#M21" NAME="L983">DESCRIPTION</A>
<DD><A HREF="scale.htm#M22" NAME="L984">WIDGET COMMAND</A>
<DL>
<DD><A HREF="scale.htm#M23" NAME="L985"><I>pathName </I><B>cget</B> <I>option</I></A>
<DD><A HREF="scale.htm#M24" NAME="L986"><I>pathName </I><B>configure</B> ?<I>option</I>? ?<I>value option value ...</I>?</A>
<DD><A HREF="scale.htm#M25" NAME="L987"><I>pathName </I><B>coords </B>?<I>value</I>?</A>
<DD><A HREF="scale.htm#M26" NAME="L988"><I>pathName </I><B>get</B> ?<I>x y</I>?</A>
<DD><A HREF="scale.htm#M27" NAME="L989"><I>pathName </I><B>identify</B> <I>x y</I></A>
<DD><A HREF="scale.htm#M28" NAME="L990"><I>pathName </I><B>set</B> <I>value</I></A>
</DL>
<DD><A HREF="scale.htm#M29" NAME="L991">BINDINGS</A>
<DL>
</DL>
<DD><A HREF="scale.htm#M30" NAME="L992">KEYWORDS</A>
</DL><HR>
<H3><A NAME="M2">NAME</A></H3>
scale - Create and manipulate scale widgets
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>scale</B> <I>pathName </I>?<I>options</I>?<BR>
<H3><A NAME="M4">STANDARD OPTIONS</A></H3>
<DL>
<DT><B><A HREF="options.htm#M-activebackground">-activebackground, activeBackground, Foreground</A></B>
<DT><B><A HREF="options.htm#M-background">-background or -bg, background, Background</A></B>
<DT><B><A HREF="options.htm#M-borderwidth">-borderwidth or -bd, borderWidth, BorderWidth</A></B>
<DT><B><A HREF="options.htm#M-cursor">-cursor, cursor, Cursor</A></B>
<DT><B><A HREF="options.htm#M-font">-font, font, Font</A></B>
<DT><B><A HREF="options.htm#M-foreground">-foreground or -fg, foreground, Foreground</A></B>
<DT><B><A HREF="options.htm#M-highlightbackground">-highlightbackground, highlightBackground, HighlightBackground</A></B>
<DT><B><A HREF="options.htm#M-highlightcolor">-highlightcolor, highlightColor, HighlightColor</A></B>
<DT><B><A HREF="options.htm#M-highlightthickness">-highlightthickness, highlightThickness, HighlightThickness</A></B>
<DT><B><A HREF="options.htm#M-orient">-orient, orient, Orient</A></B>
<DT><B><A HREF="options.htm#M-relief">-relief, relief, Relief</A></B>
<DT><B><A HREF="options.htm#M-repeatdelay">-repeatdelay, repeatDelay, RepeatDelay</A></B>
<DT><B><A HREF="options.htm#M-repeatinterval">-repeatinterval, repeatInterval, RepeatInterval</A></B>
<DT><B><A HREF="options.htm#M-takefocus">-takefocus, takeFocus, TakeFocus</A></B>
<DT><B><A HREF="options.htm#M-troughcolor">-troughcolor, troughColor, Background</A></B>
</DL>
<H3><A NAME="M5">WIDGET-SPECIFIC OPTIONS</A></H3>
<DL>
<DT>Command-Line Name: <B><A NAME="M6">-bigincrement</A></B>
<DT>Database Name: <B>bigIncrement</B>
<DT>Database Class: <B>BigIncrement</B>
<DD>Some interactions with the scale cause its value to change by
``large'' increments; this option specifies the size of the
large increments. If specified as 0, the large increments default
to 1/10 the range of the scale.
<P><DT>Command-Line Name: <B><A NAME="M7">-command</A></B>
<DT>Database Name: <B>command</B>
<DT>Database Class: <B>Command</B>
<DD>Specifies the prefix of a Tcl command to invoke whenever the scale's
value is changed via a widget command.
The actual command consists
of this option followed by a space and a real number indicating the
new value of the scale.
<P><DT>Command-Line Name: <B><A NAME="M8">-digits</A></B>
<DT>Database Name: <B>digits</B>
<DT>Database Class: <B>Digits</B>
<DD>An integer specifying how many significant digits should be retained
when converting the value of the scale to a string.
If the number is less than or equal to zero, then the scale picks
the smallest value that guarantees that every possible slider
position prints as a different string.
<P><DT>Command-Line Name: <B><A NAME="M9">-from</A></B>
<DT>Database Name: <B>from</B>
<DT>Database Class: <B>From</B>
<DD>A real value corresponding to the left or top end of the scale.
<P><DT>Command-Line Name: <B><A NAME="M10">-label</A></B>
<DT>Database Name: <B><A HREF="../TclCmd/label.htm">label</A></B>
<DT>Database Class: <B><A HREF="../TclCmd/label.htm">Label</A></B>
<DD>A string to display as a label for the scale. For
vertical scales the label is displayed just to the right of the
top end of the scale. For horizontal scales the label is displayed
just above the left end of the scale. If the option is specified
as an empty string, no label is displayed.
<P><DT>Command-Line Name: <B><A NAME="M11">-length</A></B>
<DT>Database Name: <B>length</B>
<DT>Database Class: <B>Length</B>
<DD>Specifies the desired long dimension of the scale in screen units
(i.e. any of the forms acceptable to <B><A HREF="../TclLib/GetPixels.htm">Tk_GetPixels</A></B>).
For vertical scales this is the scale's height; for horizontal scales
it is the scale's width.
<P><DT>Command-Line Name: <B><A NAME="M12">-resolution</A></B>
<DT>Database Name: <B>resolution</B>
<DT>Database Class: <B>Resolution</B>
<DD>A real value specifying the resolution for the scale.
If this value is greater than zero then the scale's value will always be
rounded to an even multiple of this value, as will tick marks and
the endpoints of the scale. If the value is less than zero then no
rounding occurs. Defaults to 1 (i.e., the value will be integral).
<P><DT>Command-Line Name: <B><A NAME="M13">-showvalue</A></B>
<DT>Database Name: <B>showValue</B>
<DT>Database Class: <B>ShowValue</B>
<DD>Specifies a boolean value indicating whether or not the current
value of the scale is to be displayed.
<P><DT>Command-Line Name: <B><A NAME="M14">-sliderlength</A></B>
<DT>Database Name: <B>sliderLength</B>
<DT>Database Class: <B>SliderLength</B>
<DD>Specfies the size of the slider, measured in screen units along the slider's
long dimension. The value may be specified in any of the forms acceptable
to <B><A HREF="../TclLib/GetPixels.htm">Tk_GetPixels</A></B>.
<P><DT>Command-Line Name: <B><A NAME="M15">-sliderrelief</A></B>
<DT>Database Name: <B>sliderRelief</B>
<DT>Database Class: <B>SliderRelief</B>
<DD>Specifies the relief to use when drawing the slider, such as <B>raised</B>
or <B>sunken</B>.
<P><DT>Command-Line Name: <B><A NAME="M16">-state</A></B>
<DT>Database Name: <B>state</B>
<DT>Database Class: <B>State</B>
<DD>Specifies one of three states for the scale: <B>normal</B>,
<B>active</B>, or <B>disabled</B>.
If the scale is disabled then the value may not be changed and the scale
won't activate.
If the scale is active, the slider is displayed using the color
specified by the <B>activeBackground</B> option.
<P><DT>Command-Line Name: <B><A NAME="M17">-tickinterval</A></B>
<DT>Database Name: <B>tickInterval</B>
<DT>Database Class: <B>TickInterval</B>
<DD>Must be a real value.
Determines the spacing between numerical
tick marks displayed below or to the left of the slider.
If 0, no tick marks will be displayed.
<P><DT>Command-Line Name: <B><A NAME="M18">-to</A></B>
<DT>Database Name: <B>to</B>
<DT>Database Class: <B>To</B>
<DD>Specifies a real value corresponding
to the right or bottom end of the scale.
This value may be either less than or greater than the <B>from</B> option.
<P><DT>Command-Line Name: <B><A NAME="M19">-variable</A></B>
<DT>Database Name: <B><A HREF="../TkCmd/variable.htm">variable</A></B>
<DT>Database Class: <B><A HREF="../TkCmd/variable.htm">Variable</A></B>
<DD>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><DT>Command-Line Name: <B><A NAME="M20">-width</A></B>
<DT>Database Name: <B>width</B>
<DT>Database Class: <B>Width</B>
<DD>Specifies the desired narrow dimension of the trough in screen units
(i.e. any of the forms acceptable to <B><A HREF="../TclLib/GetPixels.htm">Tk_GetPixels</A></B>).
For vertical scales this is the trough's width; for horizontal scales
this is the trough's height.
</DL>
<H3><A NAME="M21">DESCRIPTION</A></H3>
The <B>scale</B> command creates a new window (given by the
<I>pathName</I> 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 <B>scale</B> command returns its
<I>pathName</I> argument. At the time this command is invoked,
there must not exist a window named <I>pathName</I>, but
<I>pathName</I>'s parent must exist.
<P>
A scale is a widget that displays a rectangular <I>trough</I> and a
small <I>slider</I>. The trough corresponds to a range
of real values (determined by the <B>from</B>, <B>to</B>, and
<B>resolution</B> 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 BINDINGS
section below. Whenever the scale's value is changed, a Tcl
command is invoked (using the <B>command</B> 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 <B><A HREF="../TkCmd/variable.htm">variable</A></B>
option), so that changes in either are reflected in the other.
<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.
<H3><A NAME="M22">WIDGET COMMAND</A></H3>
The <B>scale</B> command creates a new Tcl command whose
name is <I>pathName</I>. This
command may be used to invoke various
operations on the widget. It has the following general form:
<PRE><I>pathName option </I>?<I>arg arg ...</I>?</PRE>
<I>Option</I> and the <I>arg</I>s
determine the exact behavior of the command. The following
commands are possible for scale widgets:
<P>
<DL>
<P><DT><A NAME="M23"><I>pathName </I><B>cget</B> <I>option</I></A><DD>
Returns the current value of the configuration option given
by <I>option</I>.
<I>Option</I> may have any of the values accepted by the <B>scale</B>
command.
<P><DT><A NAME="M24"><I>pathName </I><B>configure</B> ?<I>option</I>? ?<I>value option value ...</I>?</A><DD>
Query or modify the configuration options of the widget.
If no <I>option</I> is specified, returns a list describing all of
the available options for <I>pathName</I> (see <B><A HREF="../TclLib/ConfigWidg.htm">Tk_ConfigureInfo</A></B> for
information on the format of this list). If <I>option</I> is specified
with no <I>value</I>, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no <I>option</I> is specified). If
one or more <I>option-value</I> pairs are specified, then the command
modifies the given widget option(s) to have the given value(s); in
this case the command returns an empty string.
<I>Option</I> may have any of the values accepted by the <B>scale</B>
command.
<P><DT><A NAME="M25"><I>pathName </I><B>coords </B>?<I>value</I>?</A><DD>
Returns a list whose elements are the x and y coordinates of
the point along the centerline of the trough that corresponds
to <I>value</I>.
If <I>value</I> is omitted then the scale's current value is used.
<P><DT><A NAME="M26"><I>pathName </I><B>get</B> ?<I>x y</I>?</A><DD>
If <I>x</I> and <I>y</I> are omitted, returns the current value
of the scale. If <I>x</I> and <I>y</I> are specified, they give
pixel coordinates within the widget; the command returns
the scale value corresponding to the given pixel.
Only one of <I>x</I> or <I>y</I> is used: for horizontal scales
<I>y</I> is ignored, and for vertical scales <I>x</I> is ignored.
<P><DT><A NAME="M27"><I>pathName </I><B>identify</B> <I>x y</I></A><DD>
Returns a string indicating what part of the scale lies under
the coordinates given by <I>x</I> and <I>y</I>.
A return value of <B>slider</B> means that the point is over
the slider; <B>trough1</B> means that the point is over the
portion of the slider above or to the left of the slider;
and <B>trough2</B> 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><DT><A NAME="M28"><I>pathName </I><B>set</B> <I>value</I></A><DD>
This command is invoked to change the current value of the scale,
and hence the position at which the slider is displayed. <I>Value</I>
gives the new value for the scale.
The command has no effect if the scale is disabled.
<P></DL>
<H3><A NAME="M29">BINDINGS</A></H3>
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>
<P><DT>[1]<DD>
If button 1 is pressed in the trough, the scale's value will
be incremented or decremented by the value of the <B>resolution</B>
option so that the slider moves in the direction of the cursor.
If the button is held down, the action auto-repeats.
<P><DT>[2]<DD>
If button 1 is pressed over the slider, the slider can be dragged
with the mouse.
<P><DT>[3]<DD>
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><DT>[4]<DD>
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><DT>[5]<DD>
The Up and Left keys move the slider up (left) by the value
of the <B>resolution</B> option.
<P><DT>[6]<DD>
The Down and Right keys move the slider down (right) by the value
of the <B>resolution</B> option.
<P><DT>[7]<DD>
Control-Up and Control-Left move the slider up (left) by the
value of the <B>bigIncrement</B> option.
<P><DT>[8]<DD>
Control-Down and Control-Right move the slider down (right) by the
value of the <B>bigIncrement</B> option.
<P><DT>[9]<DD>
Home moves the slider to the top (left) end of its range.
<P><DT>[10]<DD>
End moves the slider to the bottom (right) end of its range.
<P></DL>
<P>
If the scale is disabled using the <B>state</B> option then
none of the above bindings have any effect.
<P>
The behavior of scales can be changed by defining new bindings for
individual widgets or by redefining the class bindings.
<H3><A NAME="M30">KEYWORDS</A></H3>
<A href="../Keywords/S.htm#scale">scale</A>, <A href="../Keywords/S.htm#slider">slider</A>, <A href="../Keywords/T.htm#trough">trough</A>, <A href="../Keywords/W.htm#widget">widget</A>
<HR><PRE>
<A HREF="../copyright.htm">Copyright</A> &#169; 1990-1994 The Regents of the University of California.
<A HREF="../copyright.htm">Copyright</A> &#169; 1994-1996 Sun Microsystems, Inc.
<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
</BODY></HTML>