1scrollbar(n) Tk Built-In Commands scrollbar(n)
2
3
4
5______________________________________________________________________________
6
8 scrollbar - Create and manipulate scrollbar widgets
9
11 scrollbar pathName ?options?
12
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
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
47
49 The scrollbar command creates a new window (given by the pathName argu‐
50 ment) and makes it into a scrollbar widget. Additional options,
51 described above, may be specified on the command line or in the option
52 database to configure aspects of the scrollbar such as its colors, ori‐
53 entation, and relief. The scrollbar command returns its pathName argu‐
54 ment. At the time this command is invoked, there must not exist a win‐
55 dow named pathName, but pathName's parent must exist.
56
57 A scrollbar is a widget that displays two arrows, one at each end of
58 the scrollbar, and a slider in the middle portion of the scrollbar. It
59 provides information about what is visible in an associated window that
60 displays a document of some sort (such as a file being edited or a
61 drawing). The position and size of the slider indicate which portion
62 of the document is visible in the associated window. For example, if
63 the slider in a vertical scrollbar covers the top third of the area
64 between the two arrows, it means that the associated window displays
65 the top third of its document.
66
67 Scrollbars can be used to adjust the view in the associated window by
68 clicking or dragging with the mouse. See the BINDINGS section below
69 for details.
70
72 A scrollbar displays five elements, which are referred to in the widget
73 commands for the scrollbar:
74
75 arrow1 The top or left arrow in the scrollbar.
76
77 trough1 The region between the slider and arrow1.
78
79 slider The rectangle that indicates what is visible in the associ‐
80 ated widget.
81
82 trough2 The region between the slider and arrow2.
83
84 arrow2 The bottom or right arrow in the scrollbar.
85
87 The scrollbar command creates a new Tcl command whose name is pathName.
88 This command may be used to invoke various operations on the widget.
89 It has the following general form:
90 pathName option ?arg arg ...?
91 Option and the args determine the exact behavior of the command. The
92 following commands are possible for scrollbar widgets:
93
94 pathName activate ?element?
95 Marks the element indicated by element as active, which causes
96 it to be displayed as specified by the activeBackground and
97 activeRelief options. The only element values understood by
98 this command are arrow1, slider, or arrow2. If any other value
99 is specified then no element of the scrollbar will be active.
100 If element is not specified, the command returns the name of the
101 element that is currently active, or an empty string if no ele‐
102 ment is active.
103
104 pathName cget option
105 Returns the current value of the configuration option given by
106 option. Option may have any of the values accepted by the
107 scrollbar command.
108
109 pathName configure ?option? ?value option value ...?
110 Query or modify the configuration options of the widget. If no
111 option is specified, returns a list describing all of the avail‐
112 able options for pathName (see Tk_ConfigureInfo for information
113 on the format of this list). If option is specified with no
114 value, then the command returns a list describing the one named
115 option (this list will be identical to the corresponding sublist
116 of the value returned if no option is specified). If one or
117 more option-value pairs are specified, then the command modifies
118 the given widget option(s) to have the given value(s); in this
119 case the command returns an empty string. Option may have any
120 of the values accepted by the scrollbar command.
121
122 pathName delta deltaX deltaY
123 Returns a real number indicating the fractional change in the
124 scrollbar setting that corresponds to a given change in slider
125 position. For example, if the scrollbar is horizontal, the
126 result indicates how much the scrollbar setting must change to
127 move the slider deltaX pixels to the right (deltaY is ignored in
128 this case). If the scrollbar is vertical, the result indicates
129 how much the scrollbar setting must change to move the slider
130 deltaY pixels down. The arguments and the result may be zero or
131 negative.
132
133 pathName fraction x y
134 Returns a real number between 0 and 1 indicating where the point
135 given by x and y lies in the trough area of the scrollbar. The
136 value 0 corresponds to the top or left of the trough, the value
137 1 corresponds to the bottom or right, 0.5 corresponds to the
138 middle, and so on. X and y must be pixel coordinates relative
139 to the scrollbar widget. If x and y refer to a point outside
140 the trough, the closest point in the trough is used.
141
142 pathName get
143 Returns the scrollbar settings in the form of a list whose ele‐
144 ments are the arguments to the most recent set widget command.
145
146 pathName identify x y
147 Returns the name of the element under the point given by x and y
148 (such as arrow1), or an empty string if the point does not lie
149 in any element of the scrollbar. X and y must be pixel coordi‐
150 nates relative to the scrollbar widget.
151
152 pathName set first last
153 This command is invoked by the scrollbar's associated widget to
154 tell the scrollbar about the current view in the widget. The
155 command takes two arguments, each of which is a real fraction
156 between 0 and 1. The fractions describe the range of the docu‐
157 ment that is visible in the associated widget. For example, if
158 first is 0.2 and last is 0.4, it means that the first part of
159 the document visible in the window is 20% of the way through the
160 document, and the last visible part is 40% of the way through.
161
163 When the user interacts with the scrollbar, for example by dragging the
164 slider, the scrollbar notifies the associated widget that it must
165 change its view. The scrollbar makes the notification by evaluating a
166 Tcl command generated from the scrollbar's -command option. The com‐
167 mand may take any of the following forms. In each case, prefix is the
168 contents of the -command option, which usually has a form like .t yview
169
170 prefix moveto fraction
171 Fraction is a real number between 0 and 1. The widget should
172 adjust its view so that the point given by fraction appears at
173 the beginning of the widget. If fraction is 0 it refers to the
174 beginning of the document. 1.0 refers to the end of the docu‐
175 ment, 0.333 refers to a point one-third of the way through the
176 document, and so on.
177
178 prefix scroll number units
179 The widget should adjust its view by number units. The units
180 are defined in whatever way makes sense for the widget, such as
181 characters or lines in a text widget. Number is either 1, which
182 means one unit should scroll off the top or left of the window,
183 or -1, which means that one unit should scroll off the bottom or
184 right of the window.
185
186 prefix scroll number pages
187 The widget should adjust its view by number pages. It is up to
188 the widget to define the meaning of a page; typically it is
189 slightly less than what fits in the window, so that there is a
190 slight overlap between the old and new views. Number is either
191 1, which means the next page should become visible, or -1, which
192 means that the previous page should become visible.
193
195 In versions of Tk before 4.0, the set and get widget commands used a
196 different form. This form is still supported for backward compatibil‐
197 ity, but it is deprecated. In the old command syntax, the set widget
198 command has the following form:
199
200 pathName set totalUnits windowUnits firstUnit lastUnit
201 In this form the arguments are all integers. TotalUnits gives
202 the total size of the object being displayed in the associated
203 widget. The meaning of one unit depends on the associated wid‐
204 get; for example, in a text editor widget units might corre‐
205 spond to lines of text. WindowUnits indicates the total number
206 of units that can fit in the associated window at one time.
207 FirstUnit and lastUnit give the indices of the first and last
208 units currently visible in the associated window (zero corre‐
209 sponds to the first unit of the object).
210
211 Under the old syntax the get widget command returns a list of four
212 integers, consisting of the totalUnits, windowUnits, firstUnit, and
213 lastUnit values from the last set widget command.
214
215 The commands generated by scrollbars also have a different form when
216 the old syntax is being used:
217
218 prefix unit
219 Unit is an integer that indicates what should appear at the top
220 or left of the associated widget's window. It has the same
221 meaning as the firstUnit and lastUnit arguments to the set wid‐
222 get command.
223
224 The most recent set widget command determines whether or not to use the
225 old syntax. If it is given two real arguments then the new syntax will
226 be used in the future, and if it is given four integer arguments then
227 the old syntax will be used.
228
230 Tk automatically creates class bindings for scrollbars that give them
231 the following default behavior. If the behavior is different for ver‐
232 tical and horizontal scrollbars, the horizontal behavior is described
233 in parentheses.
234
235 [1] Pressing button 1 over arrow1 causes the view in the associated
236 widget to shift up (left) by one unit so that the document
237 appears to move down (right) one unit. If the button is held
238 down, the action auto-repeats.
239
240 [2] Pressing button 1 over trough1 causes the view in the associated
241 widget to shift up (left) by one screenful so that the document
242 appears to move down (right) one screenful. If the button is
243 held down, the action auto-repeats.
244
245 [3] Pressing button 1 over the slider and dragging causes the view
246 to drag with the slider. If the jump option is true, then the
247 view doesn't drag along with the slider; it changes only when
248 the mouse button is released.
249
250 [4] Pressing button 1 over trough2 causes the view in the associated
251 widget to shift down (right) by one screenful so that the docu‐
252 ment appears to move up (left) one screenful. If the button is
253 held down, the action auto-repeats.
254
255 [5] Pressing button 1 over arrow2 causes the view in the associated
256 widget to shift down (right) by one unit so that the document
257 appears to move up (left) one unit. If the button is held down,
258 the action auto-repeats.
259
260 [6] If button 2 is pressed over the trough or the slider, it sets
261 the view to correspond to the mouse position; dragging the
262 mouse with button 2 down causes the view to drag with the mouse.
263 If button 2 is pressed over one of the arrows, it causes the
264 same behavior as pressing button 1.
265
266 [7] If button 1 is pressed with the Control key down, then if the
267 mouse is over arrow1 or trough1 the view changes to the very top
268 (left) of the document; if the mouse is over arrow2 or trough2
269 the view changes to the very bottom (right) of the document; if
270 the mouse is anywhere else then the button press has no effect.
271
272 [8] In vertical scrollbars the Up and Down keys have the same behav‐
273 ior as mouse clicks over arrow1 and arrow2, respectively. In
274 horizontal scrollbars these keys have no effect.
275
276 [9] In vertical scrollbars Control-Up and Control-Down have the same
277 behavior as mouse clicks over trough1 and trough2, respectively.
278 In horizontal scrollbars these keys have no effect.
279
280 [10] In horizontal scrollbars the Up and Down keys have the same
281 behavior as mouse clicks over arrow1 and arrow2, respectively.
282 In vertical scrollbars these keys have no effect.
283
284 [11] In horizontal scrollbars Control-Up and Control-Down have the
285 same behavior as mouse clicks over trough1 and trough2, respec‐
286 tively. In vertical scrollbars these keys have no effect.
287
288 [12] The Prior and Next keys have the same behavior as mouse clicks
289 over trough1 and trough2, respectively.
290
291 [13] The Home key adjusts the view to the top (left edge) of the doc‐
292 ument.
293
294 [14] The End key adjusts the view to the bottom (right edge) of the
295 document.
296
298 Create a window with a scrollable text widget:
299 toplevel .tl
300 text .tl.t -yscrollcommand {.tl.s set}
301 scrollbar .tl.s -command {.tl.t yview}
302 grid .tl.t .tl.s -sticky nsew
303 grid columnconfigure .tl 0 -weight 1
304 grid rowconfigure .tl 0 -weight 1
305
306
308 scrollbar, widget
309
310
311
312Tk 4.1 scrollbar(n)