1focus(3) User Contributed Perl Documentation focus(3)
2
3
4
6 focus - Manage the input focus
7
9 $widget->focus
10
11 $widget->focusOption
12
13 $widget->focusNext
14
15 $widget->focusPrev
16
17 $widget->focusFollowsMouse
18
20 The focus methods are used to manage the Tk input focus. At any given
21 time, one window on each display is designated as the focus window;
22 any key press or key release events for the display are sent to that
23 window. It is normally up to the window manager to redirect the focus
24 among the top-level windows of a display. For example, some window
25 managers automatically set the input focus to a top-level window
26 whenever the mouse enters it; others redirect the input focus only
27 when the user clicks on a window. Usually the window manager will set
28 the focus only to top-level windows, leaving it up to the application
29 to redirect the focus among the children of the top-level.
30
31 Tk remembers one focus window for each top-level (the most recent
32 descendant of that top-level to receive the focus); when the window
33 manager gives the focus to a top-level, Tk automatically redirects it
34 to the remembered window. Within a top-level Tk uses an explicit focus
35 model by default. Moving the mouse within a top-level does not
36 normally change the focus; the focus changes only when a widget
37 decides explicitly to claim the focus (e.g., because of a button
38 click), or when the user types a key such as Tab that moves the focus.
39
40 The method focusFollowsMouse may be invoked to create an implicit focus
41 model: it reconfigures Tk so that the focus is set to a window
42 whenever the mouse enters it. The methods focusNext and focusPrev
43 implement a focus order among the windows of a top-level; they are
44 used in the default bindings for Tab and Shift-Tab, among other things.
45
46 The focus methods can take any of the following forms:
47
48 $widget->focusCurrent
49 Returns the focus window on the display containing the $widget, or
50 an empty string if no window in this application has the focus on
51 that display.
52
53 $widget->focus
54 If the application currently has the input focus on $widget's
55 display, this command resets the input focus for $widget's display
56 to $widget and returns an empty string. If the application doesn't
57 currently have the input focus on $widget's display, $widget will
58 be remembered as the focus for its top-level; the next time the
59 focus arrives at the top-level, Tk will redirect it to $widget.
60
61 $widget->focusForce
62 Sets the focus of $widget's display to $widget, even if the
63 application doesn't currently have the input focus for the display.
64 This command should be used sparingly, if at all. In normal usage,
65 an application should not claim the focus for itself; instead, it
66 should wait for the window manager to give it the focus.
67
68 $widget->focusLastfor
69 Returns the name of the most recent window to have the input focus
70 among all the windows in the same top-level as $widget. If no
71 window in that top-level has ever had the input focus, or if the
72 most recent focus window has been deleted, then the top-level is
73 returned. The return value is the window that will receive the
74 input focus the next time the window manager gives the focus to the
75 top-level.
76
77 $widget->focusNext
78 $widget->focusPrev
79 focusNext is a utility method used for keyboard traversal, but can
80 be useful in other contexts. It sets the focus to the ``next''
81 window after $widget in focus order. The focus order is determined
82 by the stacking order of windows and the structure of the window
83 hierarchy. Among siblings, the focus order is the same as the
84 stacking order, with the lowest window being first. If a window
85 has children, the window is visited first, followed by its children
86 (recursively), followed by its next sibling. Top-level windows
87 other than $widget are skipped, so that focusNext never returns a
88 window in a different top-level from $widget.
89
90 After computing the next window, focusNext examines the window's
91 -takefocus option to see whether it should be skipped. If so,
92 focusNext continues on to the next window in the focus order, until
93 it eventually finds a window that will accept the focus or returns
94 back to $widget.
95
96 focusPrev is similar to focusNext except that it sets the focus to
97 the window just before $widget in the focus order.
98
99 $widget->focusFollowsMouse
100 focusFollowsMouse changes the focus model for the application to an
101 implicit one where the window under the mouse gets the focus.
102 After this procedure is called, whenever the mouse enters a window
103 Tk will automatically give it the input focus. The focus command
104 may be used to move the focus to a window other than the one under
105 the mouse, but as soon as the mouse moves into a new window the
106 focus will jump to that window. Note: at present there is no
107 built-in support for returning the application to an explicit focus
108 model; to do this you'll have to write a script that deletes the
109 bindings created by focusFollowsMouse.
110
112 When an internal window receives the input focus, Tk doesn't actually
113 set the X focus to that window; as far as X is concerned, the focus
114 will stay on the top-level window containing the window with the focus.
115 However, Tk generates FocusIn and FocusOut events just as if the X
116 focus were on the internal window. This approach gets around a number
117 of problems that would occur if the X focus were actually moved; the
118 fact that the X focus is on the top-level is invisible unless you use C
119 code to query the X server directly.
120
122 Note that for the Canvas widget, the call to focus has to be fully
123 qualified. This is because there is already a focus method for the
124 Canvas widget, which sets the focus on individual canvas tags.
125
126 $canvas->Tk::focus
127
129 events, focus, keyboard, top-level, window manager
130
131
132
133perl v5.12.0 2010-05-13 focus(3)