1scrollbar(n)                 Tk Built-In Commands                 scrollbar(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       scrollbar - Create and manipulate scrollbar widgets
9

SYNOPSIS

11       scrollbar pathName ?options?
12

STANDARD OPTIONS

14       -activebackground     -highlightcolor      -repeatdelay
15       -background           -highlightthickness  -repeatinterval
16       -borderwidth          -jump                -takefocus
17       -cursor               -orient              -troughcolor
18       -highlightbackground  -relief
19
20       See the options manual entry for details on the standard options.
21

WIDGET-SPECIFIC OPTIONS

23       [-activerelief activeRelief]  Specifies the relief to use when display‐
24       ing the element that is active, if any.  Elements other than the active
25       element  are always displayed with a raised relief.  [-command command]
26       Specifies the prefix of a Tcl command to invoke to change the  view  in
27       the  widget associated with the scrollbar.  When a user requests a view
28       change by manipulating the scrollbar, a Tcl command  is  invoked.   The
29       actual  command consists of this option followed by additional informa‐
30       tion as described later.  This option almost always has a value such as
31       .t  xview  or  .t  yview, consisting of the name of a widget and either
32       xview (if the scrollbar is for horizontal scrolling) or yview (for ver‐
33       tical scrolling).  All scrollable widgets have xview and yview commands
34       that take exactly the additional arguments appended by the scrollbar as
35       described  in  SCROLLING COMMANDS below.  [-elementborderwidth element‐
36       BorderWidth] Specifies the width of borders drawn around  the  internal
37       elements  of  the scrollbar (the two arrows and the slider).  The value
38       may have any of the forms acceptable to Tk_GetPixels.  If this value is
39       less  than  zero,  the  value  of the borderWidth option is used in its
40       place.  [-width width] Specifies the desired narrow  dimension  of  the
41       scrollbar  window,  not  including  3-D  border,  if any.  For vertical
42       scrollbars this will be the width and for  horizontal  scrollbars  this
43       will  be the height.  The value may have any of the forms acceptable to
44       Tk_GetPixels.
45_________________________________________________________________
46

DESCRIPTION

48       The scrollbar command creates a new window (given by the pathName argu‐
49       ment)  and  makes  it  into  a  scrollbar  widget.  Additional options,
50       described above, may be specified on the command line or in the  option
51       database to configure aspects of the scrollbar such as its colors, ori‐
52       entation, and relief.  The scrollbar command returns its pathName argu‐
53       ment.  At the time this command is invoked, there must not exist a win‐
54       dow named pathName, but pathName's parent must exist.
55
56       A scrollbar is a widget that displays two arrows, one at  each  end  of
57       the scrollbar, and a slider in the middle portion of the scrollbar.  It
58       provides information about what is visible in an associated window that
59       displays  a  document  of  some  sort (such as a file being edited or a
60       drawing).  The position and size of the slider indicate  which  portion
61       of  the  document is visible in the associated window.  For example, if
62       the slider in a vertical scrollbar covers the top  third  of  the  area
63       between  the  two  arrows, it means that the associated window displays
64       the top third of its document.
65
66       Scrollbars can be used to adjust the view in the associated  window  by
67       clicking  or  dragging  with the mouse.  See the BINDINGS section below
68       for details.
69

ELEMENTS

71       A scrollbar displays five elements, which are referred to in the widget
72       commands for the scrollbar:
73
74       arrow1    The top or left arrow in the scrollbar.
75
76       trough1   The region between the slider and arrow1.
77
78       slider    The  rectangle  that indicates what is visible in the associ‐
79                 ated widget.
80
81       trough2   The region between the slider and arrow2.
82
83       arrow2    The bottom or right arrow in the scrollbar.
84

WIDGET COMMAND

86       The scrollbar command creates a new Tcl command whose name is pathName.
87       This  command  may  be used to invoke various operations on the widget.
88       It has the following general form:
89              pathName option ?arg arg ...?
90       Option and the args determine the exact behavior of the  command.   The
91       following commands are possible for scrollbar widgets:
92
93       pathName activate ?element?
94              Marks  the  element indicated by element as active, which causes
95              it to be displayed as  specified  by  the  activeBackground  and
96              activeRelief  options.   The  only  element values understood by
97              this command are arrow1, slider, or arrow2.  If any other  value
98              is  specified  then  no element of the scrollbar will be active.
99              If element is not specified, the command returns the name of the
100              element  that is currently active, or an empty string if no ele‐
101              ment is active.
102
103       pathName cget option
104              Returns the current value of the configuration option  given  by
105              option.   Option  may  have  any  of  the values accepted by the
106              scrollbar command.
107
108       pathName configure ?option? ?value option value ...?
109              Query or modify the configuration options of the widget.  If  no
110              option is specified, returns a list describing all of the avail‐
111              able options for pathName (see Tk_ConfigureInfo for  information
112              on  the  format  of  this list).  If option is specified with no
113              value, then the command returns a list describing the one  named
114              option (this list will be identical to the corresponding sublist
115              of the value returned if no option is  specified).   If  one  or
116              more option-value pairs are specified, then the command modifies
117              the given widget option(s) to have the given value(s);  in  this
118              case  the  command returns an empty string.  Option may have any
119              of the values accepted by the scrollbar command.
120
121       pathName delta deltaX deltaY
122              Returns a real number indicating the fractional  change  in  the
123              scrollbar  setting  that corresponds to a given change in slider
124              position.  For example, if  the  scrollbar  is  horizontal,  the
125              result  indicates  how much the scrollbar setting must change to
126              move the slider deltaX pixels to the right (deltaY is ignored in
127              this  case).  If the scrollbar is vertical, the result indicates
128              how much the scrollbar setting must change to  move  the  slider
129              deltaY pixels down.  The arguments and the result may be zero or
130              negative.
131
132       pathName fraction x y
133              Returns a real number between 0 and 1 indicating where the point
134              given  by x and y lies in the trough area of the scrollbar.  The
135              value 0 corresponds to the top or left of the trough, the  value
136              1  corresponds  to  the  bottom or right, 0.5 corresponds to the
137              middle, and so on.  X and y must be pixel  coordinates  relative
138              to  the  scrollbar  widget.  If x and y refer to a point outside
139              the trough, the closest point in the trough is used.
140
141       pathName get
142              Returns the scrollbar settings in the form of a list whose  ele‐
143              ments are the arguments to the most recent set widget command.
144
145       pathName identify x y
146              Returns the name of the element under the point given by x and y
147              (such as arrow1), or an empty string if the point does  not  lie
148              in  any element of the scrollbar.  X and y must be pixel coordi‐
149              nates relative to the scrollbar widget.
150
151       pathName set first last
152              This command is invoked by the scrollbar's associated widget  to
153              tell  the  scrollbar  about the current view in the widget.  The
154              command takes two arguments, each of which is  a  real  fraction
155              between  0 and 1.  The fractions describe the range of the docu‐
156              ment that is visible in the associated widget.  For example,  if
157              first  is  0.2  and last is 0.4, it means that the first part of
158              the document visible in the window is 20% of the way through the
159              document, and the last visible part is 40% of the way through.
160

SCROLLING COMMANDS

162       When the user interacts with the scrollbar, for example by dragging the
163       slider, the scrollbar notifies  the  associated  widget  that  it  must
164       change  its view.  The scrollbar makes the notification by evaluating a
165       Tcl command generated from the scrollbar's -command option.   The  com‐
166       mand  may take any of the following forms.  In each case, prefix is the
167       contents of the -command option, which usually has a form like .t yview
168
169       prefix moveto fraction
170              Fraction is a real number between 0 and 1.   The  widget  should
171              adjust  its  view so that the point given by fraction appears at
172              the beginning of the widget.  If fraction is 0 it refers to  the
173              beginning  of  the document.  1.0 refers to the end of the docu‐
174              ment, 0.333 refers to a point one-third of the way  through  the
175              document, and so on.
176
177       prefix scroll number units
178              The  widget  should  adjust its view by number units.  The units
179              are defined in whatever way makes sense for the widget, such  as
180              characters or lines in a text widget.  Number is either 1, which
181              means one unit should scroll off the top or left of the  window,
182              or -1, which means that one unit should scroll off the bottom or
183              right of the window.
184
185       prefix scroll number pages
186              The widget should adjust its view by number pages.  It is up  to
187              the  widget  to  define  the meaning of a page;  typically it is
188              slightly less than what fits in the window, so that there  is  a
189              slight  overlap between the old and new views.  Number is either
190              1, which means the next page should become visible, or -1, which
191              means that the previous page should become visible.
192

OLD COMMAND SYNTAX

194       In  versions  of  Tk before 4.0, the set and get widget commands used a
195       different form.  This form is still supported for backward  compatibil‐
196       ity,  but  it is deprecated.  In the old command syntax, the set widget
197       command has the following form:
198
199       pathName set totalUnits windowUnits firstUnit lastUnit
200              In this form the arguments are all integers.   TotalUnits  gives
201              the  total  size of the object being displayed in the associated
202              widget.  The meaning of one unit depends on the associated  wid‐
203              get;   for  example,  in a text editor widget units might corre‐
204              spond to lines of text.  WindowUnits indicates the total  number
205              of  units  that  can  fit  in the associated window at one time.
206              FirstUnit and lastUnit give the indices of the  first  and  last
207              units  currently  visible  in the associated window (zero corre‐
208              sponds to the first unit of the object).
209
210       Under the old syntax the get widget command  returns  a  list  of  four
211       integers,  consisting  of  the  totalUnits, windowUnits, firstUnit, and
212       lastUnit values from the last set widget command.
213
214       The commands generated by scrollbars also have a  different  form  when
215       the old syntax is being used:
216
217       prefix unit
218              Unit  is an integer that indicates what should appear at the top
219              or left of the associated widget's  window.   It  has  the  same
220              meaning  as the firstUnit and lastUnit arguments to the set wid‐
221              get command.
222
223       The most recent set widget command determines whether or not to use the
224       old syntax.  If it is given two real arguments then the new syntax will
225       be used in the future, and if it is given four integer  arguments  then
226       the old syntax will be used.
227

BINDINGS

229       Tk  automatically  creates class bindings for scrollbars that give them
230       the following default behavior.  If the behavior is different for  ver‐
231       tical  and  horizontal scrollbars, the horizontal behavior is described
232       in parentheses.
233
234       [1]    Pressing button 1 over arrow1 causes the view in the  associated
235              widget  to  shift  up  (left)  by  one unit so that the document
236              appears to move down (right) one unit.  If the  button  is  held
237              down, the action auto-repeats.
238
239       [2]    Pressing button 1 over trough1 causes the view in the associated
240              widget to shift up (left) by one screenful so that the  document
241              appears  to  move  down (right) one screenful.  If the button is
242              held down, the action auto-repeats.
243
244       [3]    Pressing button 1 over the slider and dragging causes  the  view
245              to  drag  with the slider.  If the jump option is true, then the
246              view does not drag along with the slider;  it changes only  when
247              the mouse button is released.
248
249       [4]    Pressing button 1 over trough2 causes the view in the associated
250              widget to shift down (right) by one screenful so that the  docu‐
251              ment  appears to move up (left) one screenful.  If the button is
252              held down, the action auto-repeats.
253
254       [5]    Pressing button 1 over arrow2 causes the view in the  associated
255              widget  to  shift  down (right) by one unit so that the document
256              appears to move up (left) one unit.  If the button is held down,
257              the action auto-repeats.
258
259       [6]    If  button  2  is pressed over the trough or the slider, it sets
260              the view to correspond to  the  mouse  position;   dragging  the
261              mouse with button 2 down causes the view to drag with the mouse.
262              If button 2 is pressed over one of the  arrows,  it  causes  the
263              same behavior as pressing button 1.
264
265       [7]    If  button  1  is pressed with the Control key down, then if the
266              mouse is over arrow1 or trough1 the view changes to the very top
267              (left)  of the document;  if the mouse is over arrow2 or trough2
268              the view changes to the very bottom (right) of the document;  if
269              the mouse is anywhere else then the button press has no effect.
270
271       [8]    In vertical scrollbars the Up and Down keys have the same behav‐
272              ior as mouse clicks over arrow1 and  arrow2,  respectively.   In
273              horizontal scrollbars these keys have no effect.
274
275       [9]    In vertical scrollbars Control-Up and Control-Down have the same
276              behavior as mouse clicks over trough1 and trough2, respectively.
277              In horizontal scrollbars these keys have no effect.
278
279       [10]   In  horizontal  scrollbars  the  Up  and Down keys have the same
280              behavior as mouse clicks over arrow1 and  arrow2,  respectively.
281              In vertical scrollbars these keys have no effect.
282
283       [11]   In  horizontal  scrollbars  Control-Up and Control-Down have the
284              same behavior as mouse clicks over trough1 and trough2,  respec‐
285              tively.  In vertical scrollbars these keys have no effect.
286
287       [12]   The  Prior  and Next keys have the same behavior as mouse clicks
288              over trough1 and trough2, respectively.
289
290       [13]   The Home key adjusts the view to the top (left edge) of the doc‐
291              ument.
292
293       [14]   The  End  key adjusts the view to the bottom (right edge) of the
294              document.
295

EXAMPLE

297       Create a window with a scrollable text widget:
298              toplevel .tl
299              text .tl.t -yscrollcommand {.tl.s set}
300              scrollbar .tl.s -command {.tl.t yview}
301              grid .tl.t .tl.s -sticky nsew
302              grid columnconfigure .tl 0 -weight 1
303              grid rowconfigure .tl 0 -weight 1
304

SEE ALSO

306       ttk:scrollbar(n)
307

KEYWORDS

309       scrollbar, widget
310
311
312
313Tk                                    4.1                         scrollbar(n)
Impressum