1Widget(3)             User Contributed Perl Documentation            Widget(3)
2
3
4

NAME

6       Tk::Widget - Base class of all widgets
7

SYNOPSIS

9          package Tk::Whatever;
10          require Tk::Widget;
11          @ISA = qw(Tk::Widget);
12          Construct Tk::Widget 'Whatever';
13
14          sub Tk_cmd { \&Tk::whatever }
15
16        $widget->method(?arg, arg, ...?)
17

DESCRIPTION

19       The Tk::Widget is an abstract base class for all Tk widgets.
20
21       Generic methods available to all widgets include the methods based on
22       core "winfo" mechanism and are used to retrieve information about win‐
23       dows managed by Tk. They can take any of a number of different forms,
24       depending on the method.  The legal forms are:
25
26       $widget->appname?(newName)?
27           If newName isn't specified, this method returns the name of the
28           application (the name that may be used in send commands to communi‐
29           cate with the application).  If newName is specified, then the name
30           of the application is changed to newName.  If the given name is
31           already in use, then a suffix of the form `` #2'' or `` #3'' is
32           appended in order to make the name unique.  The method's result is
33           the name actually chosen.  newName should not start with a capital
34           letter.  This will interfere with option processing, since names
35           starting with capitals are assumed to be classes;  as a result, Tk
36           may not be able to find some options for the application.  If sends
37           have been disabled by deleting the send command, this command will
38           reenable them and recreate the send command.
39
40       $widget->atom(name)
41           Returns a decimal string giving the integer identifier for the atom
42           whose name is name.  If no atom exists with the name name then a
43           new one is created.
44
45       $widget->atomname(id)
46           Returns the textual name for the atom whose integer identifier is
47           id.  This command is the inverse of the $widget->atom command.  It
48           generates an error if no such atom exists.
49
50       $widget->bell( ?-nice? );
51           This command rings the bell on the display for $widget and returns
52           an empty string.  The command uses the current bell-related set‐
53           tings for the display, which may be modified with programs such as
54           xset.
55
56           If -nice  is  not specified, this command also resets the screen
57           saver for the screen.  Some screen savers will ignore this, but
58           others  will reset so that the screen becomes visible again.
59
60       $widget->bindDump
61           This command returns a list of strings suitable for printing
62           detailing binding information for a widget.  It prints a widget's
63           bindtags.  For each binding tag it prints all the bindings, com‐
64           prised of the event descriptor and the callback.  Callback argu‐
65           ments are printed, and Tk::Ev objects are expanded.
66
67       $widget->Busy?(?-recurse => 1?,-option => value?)?
68           This method configures a -cursor option for $widget and (if
69           -recurse = 1> is specified) all its descendants. The cursor to be
70           set may be passed as -cursor = cursor> or defaults to 'watch'.
71           Additional configure options are applied to $widget only.  It also
72           adds a special tag 'Busy' to the bindtags of the widgets so config‐
73           ured so that  KeyPress, KeyRelease, ButtonPress and ButtonRelease
74           events are ignored (with press events generating a call to bell).
75           It then acquires a local grab for $widget.  The state of the wid‐
76           gets and the grab is restored by a call to $widget->Unbusy.
77
78       $widget->caret( ?-x => x?, ?-y => y?, ?-height => height? );
79           Sets and queries the caret location for the display of the speci‐
80           fied Tk window window.  The caret is the per-display cursor loca‐
81           tion used for indicating global focus (e.g. to comply with Micro‐
82           soft Accessibility guidelines), as well as for location of the
83           over-the-spot XIM (X Input Methods) or Windows IME windows. If no
84           options are specified, the last values used for setting the caret
85           are return in option-value pair format.  -x and -y represent win‐
86           dow-relative coordinates, and -height is the height of the current
87           cursor location, or the height of the specified window if none is
88           given.
89
90       $widget->cells
91           Returns a decimal string giving the number of cells in the color
92           map for $widget.
93
94       $widget->children
95           $widget->children Returns a list containing all the children of
96           $widget.  The list is in stacking order, with the lowest window
97           first.  Top-level windows are returned as children of their logical
98           parents.
99
100       $widget->class
101           Returns the class name for $widget.
102
103       $widget->colormapfull
104           Returns 1 if the colormap for $widget is known to be full, 0 other‐
105           wise.  The colormap for a window is ``known'' to be full if the
106           last attempt to allocate a new color on that window failed and this
107           application hasn't freed any colors in the colormap since the
108           failed allocation.
109
110       $widget->ConfigSpecs
111           Used to perform delegated option configuration for a mega-widget.
112           Returns, in Tk::Derived::ConfigSpecs notation (see Tk::Con‐
113           figSpecs), all possible options for a widget. For example,
114
115            $s = $self->Scale;
116            $self->ConfigSpecs(
117                $s->ConfigSpecs,
118                .... more ConfigSpecs specifications
119            );
120
121           returns a hash of all Tk::Scale options, delegated to $s - e.g.
122           some representative examples:
123
124            -bigincrement => [$s, bigIncrement, BigIncrement, 0, 0]
125            -digits       => [$s, digits, Digits, 0, 0]
126            -sliderlength => [$s, sliderLength, SliderLength, 10m, 30]
127            -troughcolor  => [$s, troughColor, Background, #c3c3c3, #c3c3c3]
128
129           This provides an easy means of populating a mega-widget's Con‐
130           figSpecs with initializers.
131
132       $widget->containing(rootX,rootY)
133           Returns the window containing the point given by rootX and rootY.
134           RootX and rootY are specified in screen units (i.e.  any form
135           acceptable to Tk_GetPixels) in the coordinate system of the root
136           window (if a virtual-root window manager is in use then the coordi‐
137           nate system of the virtual root window is used).  If no window in
138           this application contains the point then an empty string is
139           returned.  In selecting the containing window, children are given
140           higher priority than parents and among siblings the highest one in
141           the stacking order is chosen.
142
143       $widget->depth
144           Returns a decimal string giving the depth of $widget (number of
145           bits per pixel).
146
147       $widget->destroy
148           This command deletes the window related to $widget, plus all its
149           descendants.  If all the MainWindows are deleted then the entire
150           application will be destroyed.
151
152           The perl object $widget continues to exist while references to it
153           still exist, e.g. until variable goes out of scope.  However any
154           attempt to use Tk methods on the object will fail.  Exists($widget)
155           will return false on such objects.
156
157           Note however that while a window exists for $widget the perl object
158           is maintained (due to "references" in perl/Tk internals) even
159           though original variables may have gone out of scope.  (Normally
160           this is intuitive.)
161
162       Exists($widget)
163           Returns 1 if there exists a window for $widget, 0 if no such window
164           exists.
165
166       $widget->font(option?, arg, arg, ...?)
167           Create and inspect fonts. See Tk::Font for further details.
168
169       $widget->fpixels(number)
170           Returns a floating-point value giving the number of pixels in $wid‐
171           get corresponding to the distance given by number.  Number may be
172           specified in any of the forms acceptable to Tk_GetScreenMM, such as
173           ``2.0c'' or ``1i''.  The return value may be fractional;  for an
174           integer value, use $widget->pixels.
175
176       $widget->Getimage(name)
177           Given name, look for an image file with that base name and return a
178           Tk::Image.  File extensions are tried in this order: xpm, gif, ppm,
179           xbm until a valid iamge is found.  If no image is found, try a
180           builtin image with that name.
181
182       $widget->geometry
183           Returns the geometry for $widget, in the form widthxheight+x+y.
184           All dimensions are in pixels.
185
186       $widget->height
187           Returns a decimal string giving $widget's height in pixels.  When a
188           window is first created its height will be 1 pixel;  the height
189           will eventually be changed by a geometry manager to fulfill the
190           window's needs.  If you need the true height immediately after cre‐
191           ating a widget, invoke update to force the geometry manager to
192           arrange it, or use $widget->reqheight to get the window's requested
193           height instead of its actual height.
194
195       $widget->id
196           Returns a hexadecimal string giving a low-level platform-specific
197           identifier for $widget.  On Unix platforms, this is the X window
198           identifier.  Under Windows, this is the Windows HWND.  On the Mac‐
199           intosh the value has no meaning outside Tk.
200
201       $widget->idletasks
202           One of two methods which are used to bring the application ``up to
203           date'' by entering the event loop repeated until all pending events
204           (including idle callbacks) have been processed.
205
206           If the idletasks method is specified, then no new events or errors
207           are processed; only idle callbacks are invoked. This causes opera‐
208           tions that are normally deferred, such as display updates and win‐
209           dow layout calculations, to be performed immediately.
210
211           The idletasks command is useful in scripts where changes have been
212           made to the application's state and you want those changes to
213           appear on the display immediately, rather than waiting for the
214           script to complete. Most display updates are performed as idle
215           callbacks, so idletasks will cause them to run. However, there are
216           some kinds of updates that only happen in response to events, such
217           as those triggered by window size changes; these updates will not
218           occur in idletasks.
219
220       $widget->interps
221           Returns a list whose members are the names of all Tcl interpreters
222           (e.g. all Tk-based applications) currently registered for a partic‐
223           ular display.  The return value refers to the display of $widget.
224
225       $widget->ismapped
226           Returns 1 if $widget is currently mapped, 0 otherwise.
227
228       $widget->lower(?belowThis?)
229           If the belowThis argument is omitted then the command lowers $wid‐
230           get so that it is below all of its siblings in the stacking order
231           (it will be obscured by any siblings that overlap it and will not
232           obscure any siblings).  If belowThis is specified then it must be
233           the path name of a window that is either a sibling of $widget or
234           the descendant of a sibling of $widget.  In this case the lower
235           command will insert $widget into the stacking order just below
236           belowThis (or the ancestor of belowThis that is a sibling of $wid‐
237           get); this could end up either raising or lowering $widget.
238
239       $widget->MapWindow
240           Cause $widget to be "mapped" i.e. made visible on the display.  May
241           confuse the geometry manager (pack, grid, place, ...)  that thinks
242           it is managing the widget.
243
244       $widget->manager
245           Returns the name of the geometry manager currently responsible for
246           $widget, or an empty string if $widget isn't managed by any geome‐
247           try manager.  The name is usually the name of the method for the
248           geometry manager, such as pack or place.  If the geometry manager
249           is a widget, such as canvases or text, the name is the widget's
250           class command, such as canvas.
251
252       $widget->name
253           Returns $widget's name (i.e. its name within its parent, as opposed
254           to its full path name).  The command $mainwin->name will return the
255           name of the application.
256
257       $widget->OnDestroy(callback);
258           OnDestroy accepts a standard perl/Tk callback.  When the window
259           associated with $widget is destroyed then the callback is invoked.
260           Unlike $widget->bind('<Destroy>',...)  the widgets methods are
261           still available when callback is executed, so (for example) a Text
262           widget can save its contents to a file.
263
264           OnDestroy was required for new after mechanism.
265
266       $widget->parent
267           Returns $widget's parent, or an empty string if $widget is the main
268           window of the application.
269
270       $widget->PathName
271           Returns the Tk path name of $widget. This is the inverse of the
272           "Widget" method. (This is an import from the C interface.)
273
274       $widget->pathname(id)
275           Returns an object whose X identifier is id.  The identifier is
276           looked up on the display of $widget.  Id must be a decimal, hexa‐
277           decimal, or octal integer and must correspond to a window in the
278           invoking application, or an error occurs which can be trapped with
279           "eval { }" or "Tk::catch { }".  If the window belongs to the appli‐
280           cation, but is not an object (for example wrapper windows, HList
281           header, etc.) then "undef" is returned.
282
283       $widget->pixels(number)
284           Returns the number of pixels in $widget corresponding to the dis‐
285           tance given by number.  Number may be specified in any of the forms
286           acceptable to Tk_GetPixels, such as ``2.0c'' or ``1i''.  The result
287           is rounded to the nearest integer value;  for a fractional result,
288           use $widget->fpixels.
289
290       $widget->pointerx
291           If the mouse pointer is on the same screen as $widget, returns the
292           pointer's x coordinate, measured in pixels in the screen's root
293           window.  If a virtual root window is in use on the screen, the
294           position is measured in the virtual root.  If the mouse pointer
295           isn't on the same screen as $widget then -1 is returned.
296
297       $widget->pointerxy
298           If the mouse pointer is on the same screen as $widget, returns a
299           list with two elements, which are the pointer's x and y coordinates
300           measured in pixels in the screen's root window.  If a virtual root
301           window is in use on the screen, the position is computed in the
302           virtual root.  If the mouse pointer isn't on the same screen as
303           $widget then both of the returned coordinates are -1.
304
305       $widget->pointery
306           If the mouse pointer is on the same screen as $widget, returns the
307           pointer's y coordinate, measured in pixels in the screen's root
308           window.  If a virtual root window is in use on the screen, the
309           position is computed in the virtual root.  If the mouse pointer
310           isn't on the same screen as $widget then -1 is returned.
311
312       $widget->raise(?aboveThis?)
313           If the aboveThis argument is omitted then the command raises $wid‐
314           get so that it is above all of its siblings in the stacking order
315           (it will not be obscured by any siblings and will obscure any sib‐
316           lings that overlap it).  If aboveThis is specified then it must be
317           the path name of a window that is either a sibling of $widget or
318           the descendant of a sibling of $widget.  In this case the raise
319           command will insert $widget into the stacking order just above
320           aboveThis (or the ancestor of aboveThis that is a sibling of $wid‐
321           get); this could end up either raising or lowering $widget.
322
323       $widget->reqheight
324           Returns a decimal string giving $widget's requested height, in pix‐
325           els.  This is the value used by $widget's geometry manager to com‐
326           pute its geometry.
327
328       $widget->reqwidth
329           Returns a decimal string giving $widget's requested width, in pix‐
330           els.  This is the value used by $widget's geometry manager to com‐
331           pute its geometry.
332
333       $widget->rgb(color)
334           Returns a list containing three decimal values, which are the red,
335           green, and blue intensities that correspond to color in the window
336           given by $widget.  Color may be specified in any of the forms
337           acceptable for a color option.
338
339       $widget->rootx
340           Returns a decimal string giving the x-coordinate, in the root win‐
341           dow of the screen, of the upper-left corner of $widget's border (or
342           $widget if it has no border).
343
344       $widget->rooty
345           Returns a decimal string giving the y-coordinate, in the root win‐
346           dow of the screen, of the upper-left corner of $widget's border (or
347           $widget if it has no border).
348
349       $widget->scaling?(number)?
350           Sets and queries the current scaling factor used by Tk to convert
351           between physical units (for example, points, inches, or millime‐
352           ters) and pixels.  The number argument is a floating point number
353           that specifies the number of pixels per point on $widget's display.
354           If the number argument is omitted, the current value of the scaling
355           factor is returned.
356
357           A ``point'' is a unit of measurement equal to 1/72 inch.  A scaling
358           factor of 1.0 corresponds to 1 pixel per point, which is equivalent
359           to a standard 72 dpi monitor.  A scaling factor of 1.25 would mean
360           1.25 pixels per point, which is the setting for a 90 dpi monitor;
361           setting the scaling factor to 1.25 on a 72 dpi monitor would cause
362           everything in the application to be displayed 1.25 times as large
363           as normal.  The initial value for the scaling factor is set when
364           the application starts, based on properties of the installed moni‐
365           tor (as reported via the window system), but it can be changed at
366           any time.  Measurements made after the scaling factor is changed
367           will use the new scaling factor, but it is undefined whether exist‐
368           ing widgets will resize themselves dynamically to accomodate the
369           new scaling factor.
370
371       $widget->screen
372           Returns the name of the screen associated with $widget, in the form
373           displayName.screenIndex.
374
375       $widget->screencells
376           Returns a decimal string giving the number of cells in the default
377           color map for $widget's screen.
378
379       $widget->screendepth
380           Returns a decimal string giving the depth of the root window of
381           $widget's screen (number of bits per pixel).
382
383       $widget->screenheight
384           Returns a decimal string giving the height of $widget's screen, in
385           pixels.
386
387       $widget->screenmmheight
388           Returns a decimal string giving the height of $widget's screen, in
389           millimeters.
390
391       $widget->screenmmwidth
392           Returns a decimal string giving the width of $widget's screen, in
393           millimeters.
394
395       $widget->screenvisual
396           Returns one of the following strings to indicate the default visual
397           class for $widget's screen: directcolor, grayscale, pseudocolor,
398           staticcolor, staticgray, or truecolor.
399
400       $widget->screenwidth
401           Returns a decimal string giving the width of $widget's screen, in
402           pixels.
403
404       $widget->server
405           Returns a string containing information about the server for $wid‐
406           get's display.  The exact format of this string may vary from plat‐
407           form to platform.  For X servers the string has the form ``Xmajor‐
408           Rminor vendor vendorVersion'' where major and minor are the version
409           and revision numbers provided by the server (e.g., X11R5), vendor
410           is the name of the vendor for the server, and vendorRelease is an
411           integer release number provided by the server.
412
413       $widget->toplevel
414           Returns the reference of the top-level window containing $widget.
415
416       $widget->Unbusy
417           Restores widget state after a call to  $widget->Busy.
418
419       $widget->UnmapWindow
420           Cause $widget to be "unmapped" i.e. removed from the display.  This
421           does for any widget what $widget->withdraw does for toplevel wid‐
422           gets. May confuse the geometry manager (pack, grid, place, ...)
423           that thinks it is managing the widget.
424
425       $widget->update
426           One of two methods which are used to bring the application ``up to
427           date'' by entering the event loop repeated until all pending events
428           (including idle callbacks) have been processed.
429
430           The update method is useful in scripts where you are performing a
431           long-running computation but you still want the application to
432           respond to events such as user interactions; if you occasionally
433           call update then user input will be processed during the next call
434           to update.
435
436       $widget->useinputmethods( ?boolean? )
437           Sets and queries the state of whether Tk should use XIM (X Input
438           Methods) for filtering events.  The resulting state is returned.
439           XIM  is  used  in some locales (ie: Japanese, Korean), to handle
440           special input devices.  This feature is only significant  on  X.
441           If  XIM support is not available, this will always return 0.  If
442           the  boolean  argument  is  omitted,  the  current  state is
443           returned.  This is turned on by default for the main display.
444
445       $widget->viewable
446           Returns 1 if $widget and all of its ancestors up through the near‐
447           est toplevel window are mapped.  Returns 0 if any of these windows
448           are not mapped.
449
450       $widget->visual
451           Returns one of the following strings to indicate the visual class
452           for $widget: directcolor, grayscale, pseudocolor, staticcolor,
453           staticgray, or truecolor.
454
455       $widget->visualid
456           Returns the X identifier for the visual for $widget.
457
458       $widget->visualsavailable(?includeids?)
459           Returns a list whose elements describe the visuals available for
460           $widget's screen.  Each element consists of a visual class followed
461           by an integer depth.  The class has the same form as returned by
462           $widget->visual.  The depth gives the number of bits per pixel in
463           the visual.  In addition, if the includeids argument is provided,
464           then the depth is followed by the X identifier for the visual.
465
466       $widget->vrootheight
467           Returns the height of the virtual root window associated with $wid‐
468           get if there is one;  otherwise returns the height of $widget's
469           screen.
470
471       $widget->vrootwidth
472           Returns the width of the virtual root window associated with $wid‐
473           get if there is one;  otherwise returns the width of $widget's
474           screen.
475
476       $widget->vrootx
477           Returns the x-offset of the virtual root window associated with
478           $widget, relative to the root window of its screen.  This is nor‐
479           mally either zero or negative.  Returns 0 if there is no virtual
480           root window for $widget.
481
482       $widget->vrooty
483           Returns the y-offset of the virtual root window associated with
484           $widget, relative to the root window of its screen.  This is nor‐
485           mally either zero or negative.  Returns 0 if there is no virtual
486           root window for $widget.
487
488       $widget->waitVariable(\$name)
489       $widget->waitVisibility
490       $widget->waitWindow
491           The tk wait methods wait for one of several things to happen, then
492           it returns without taking any other actions.  The return value is
493           always an empty string.  waitVariable expects a reference to a perl
494           variable and the command waits for that variable to be modified.
495           This form is typically used to wait for a user to finish interact‐
496           ing with a dialog which sets the variable as part (possibly final)
497           part of the interaction.  waitVisibility waits for a change in
498           $widget's visibility state (as indicated by the arrival of a Visi‐
499           bilityNotify event).  This form is typically used to wait for a
500           newly-created window to appear on the screen before taking some
501           action.  waitWindow waits for $widget to be destroyed.  This form
502           is typically used to wait for a user to finish interacting with a
503           dialog box before using the result of that interaction.  Note that
504           creating and destroying the window each time a dialog is required
505           makes code modular but imposes overhead which can be avoided by
506           withdrawing the window instead and using waitVisibility.
507
508           While the tk wait methods are waiting they processes events in the
509           normal fashion, so the application will continue to respond to user
510           interactions.  If an event handler invokes tkwait again, the nested
511           call to tkwait must complete before the outer call can complete.
512
513       $widget->Walk(proc?, arg, ...?)
514           Traverse a widget hierarchy starting at $widget while executing the
515           subroutine proc to every visited widget. The arguments arg, ...
516           are supplied to the subroutine.
517
518       $widget->Widget(pathname)
519           Returns the widget reference for the given Tk path name, or "undef"
520           if the path name does not match a Tk widget. This is the inverse of
521           the "PathName" method. (This is an import from the C interface.)
522
523       $widget->width
524           Returns a decimal string giving $widget's width in pixels.  When a
525           window is first created its width will be 1 pixel;  the width will
526           eventually be changed by a geometry manager to fulfill the window's
527           needs.  If you need the true width immediately after creating a
528           widget, invoke update to force the geometry manager to arrange it,
529           or use $widget->reqwidth to get the window's requested width
530           instead of its actual width.
531
532       $widget->windowingsystem
533           Returns the current Tk windowing system, one of x11 (X11-based),
534           win32 (MS Windows), classic (Mac OS Classic), or aqua (Mac OS  X
535           Aqua).
536
537       $widget->x
538           Returns a decimal string giving the x-coordinate, in $widget's par‐
539           ent, of the upper-left corner of $widget's border (or $widget if it
540           has no border).
541
542       $widget->y
543           Returns a decimal string giving the y-coordinate, in $widget's par‐
544           ent, of the upper-left corner of $widget's border (or $widget if it
545           has no border).
546

CAVEATS

548       The above documentaion on generic methods is incomplete.
549

KEYWORDS

551       atom, children, class, geometry, height, identifier, information,
552       interpreters, mapped, parent, path name, screen, virtual root, width,
553       window
554
555
556
557perl v5.8.8                       2008-02-05                         Widget(3)
Impressum