## Tcl9.0.3/Tk9.0.3 Documentation > Tk Commands > focus

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

focus — 入力の注目の管理 Manage the input focus

### 構文 SYNOPSIS

focus
focus window
focus option ?arg ...?

### 説明 DESCRIPTION

focus 命令は Tk 入力の注目の管理に使われる｡何時の時点でも､それぞれの表示装置毎に一つの窓が注目のある窓になるよう設計されている､その表示装置へのどれかの打鍵､又は離鍵行事はその窓に送られる｡通常は画面の頂上水準の窓の間の注目の仕向け先変更は､窓管理譜宛に送られる｡譬えば､ある窓は何時でもマウスが頂上水準窓にはいると自動的に入力の注目をそこに設定する; その他の窓は入力の注目を使用者が窓を軽叩した時にのみ場所替えする｡通常､窓管理譜は注目を頂上水準窓にのみに設定する､注目を頂上水準の子供の間に移転することは応用譜に託す｡ The focus command is used to manage the Tk input focus. At any given time, one window on each display is designated as the focus window; any key press or key release events for the display are sent to that window. It is normally up to the window manager to redirect the focus among the top-level windows of a display. For example, some window managers automatically set the input focus to a top-level window whenever the mouse enters it; others redirect the input focus only when the user clicks on a window. Usually the window manager will set the focus only to top-level windows, leaving it up to the application to redirect the focus among the children of the top-level.

Tk はそれぞれの頂上水準の注目のある一つの窓を記憶する(注目を受取る最も最近の頂上水準の子孫); 窓管理譜が注目を頂上水準窓に与える時､ Tk は自動的に記憶している窓に配置換えをする｡頂上水準の内部で Tk は省略時設定では明示的な注目の模型を使う｡頂上水準の内部で のマウスの移動は通常､注目を変更しない; 注目は､部品が明示的に注目を宣言することを決定する(譬えば､釦の軽叩の故に)時か､使用者が注目を動かすようなタブの如き鍵を打鍵した時に変更する｡ Tk remembers one focus window for each top-level (the most recent descendant of that top-level to receive the focus); when the window manager gives the focus to a top-level, Tk automatically redirects it to the remembered window. Within a top-level Tk uses an explicit focus model by default. Moving the mouse within a top-level does not normally change the focus; the focus changes only when a widget decides explicitly to claim the focus (e.g., because of a button click), or when the user types a key such as Tab that moves the focus.

Tcl 手続函数の tk_focusFollowsMouse は明示的な注目の模型を作成する為に起動されるかもしれない: それはマウスが窓に入ると何時でもそこに注目が設定されるようにTk を再構成設定する｡ Tcl 手続函数の focusNext と tk_focusPrev は頂上水準の窓の間の注目の順序を実装する; それらはタブ鍵とシフト-タブ鍵 について､他の事柄との省略時設定の束縛の中につかわれる｡ The Tcl procedure tk_focusFollowsMouse may be invoked to create an implicit focus model: it reconfigures Tk so that the focus is set to a window whenever the mouse enters it. The Tcl procedures tk_focusNext and tk_focusPrev implement a focus order among the windows of a top-level; they are used in the default bindings for Tab and Shift-Tab, among other things.

focus命令は次のどの形式も採り得る: The focus command can take any of the following forms:

focus
  応用譜の主たる窓を含む画像装置の注目を得ている窓の経路名を返すか､応用譜がその装置に注目を有していない場合は空文字列を返す｡註意: 複数の画像装置を使う応用譜内で､命令符号が動くように､ -displayof (下参照)を使って画像装置を明示するほうが好ましい｡ Returns the path name of the focus window on the display containing the application's main window, or an empty string if no window in this application has the focus on that display. Note: it is better to specify the display explicitly using -displayof (see below) so that the code will work in applications using multiple displays.

focus window
  もし応用譜が window のある画像装置に現在入力の注目を有していると､この命令は window のある画像装置の注目を window に再設定し空文字列を返す｡もし応用譜が window のある画像装置に現在入力の注目を有していないと､ window は頂上水準の注目として記憶される; 次回注目が頂点水準に届いた時 Tk はをそれを window に向先変更する｡もし､ window が空文字列であると命令は何もしない｡ If the application currently has the input focus on window's display, this command resets the input focus for window's display to window and returns an empty string. If the application does not currently have the input focus on window's display, window will be remembered as the focus for its top-level; the next time the focus arrives at the top-level, Tk will redirect it to window. If window is an empty string then the command does nothing.

focus -displayof window
  window を含んでいる画像装置上の注目のある窓の名前を返す｡もし､ window の画像装置の注目のある窓がこの応用譜の中にない場合､返る値は空文字列になる｡ Returns the name of the focus window on the display containing window. If the focus window for window's display is not in this application, the return value is an empty string.

focus -force window
  window のある画像装置の注目を､たとえ応用譜が現在その装置の入力の注目を持っていなくても､ window に置く｡この命令はできるだけ控えめに使うべきである｡通常の用途では､応用譜は自身への注目を宣言すべきではない; そうではなく､窓管理譜がそれに注目を与えるまで待つべきである｡もし window が空ならこの命令はなにもしない｡ Sets the focus of window's display to window, even if the application does not currently have the input focus for the display. This command should be used sparingly, if at all. In normal usage, an application should not claim the focus for itself; instead, it should wait for the window manager to give it the focus. If window is an empty string then the command does nothing.

focus -lastfor window
  window と同じ頂上水準の中で最も最近に入力の注目を有していた窓の名前を返す｡もし入力の注目を有する頂上水準の窓がないか､最も最近注目を有していた窓が既に削除されていると頂上水準の名前が返される｡返って来る値は次回､窓管理譜が頂上水準に注目を与える時に注目を受取る窓の名前である｡ Returns the name of the most recent window to have the input focus among all the windows in the same top-level as window. If no window in that top-level has ever had the input focus, or if the most recent focus window has been deleted, then the name of the top-level is returned. The return value is the window that will receive the input focus the next time the window manager gives the focus to the top-level.

### 蛇足 QUIRKS

内部の窓が注目を受取る時､ Tk は実際は､ その窓にX の注目を設定はしない; X に関する限り､注目は頂上水準の注目を有している窓を含む窓に留まる｡しかし､ Tk は恰も X の注目が内部の窓にあるかの如く FocusIn や FocusOut 行事を生成する｡この方法はもし X の注目が実際に移動している場合におこりうる数多くの問題を回避する; 事実､頂上水準の X の注目は C 言語の命令で X 集中管理譜に直接問い合わせしない限り目視できない｡ When an internal window receives the input focus, Tk does not actually set the X focus to that window; as far as X is concerned, the focus will stay on the top-level window containing the window with the focus. However, Tk generates FocusIn and FocusOut events just as if the X focus were on the internal window. This approach gets around a number of problems that would occur if the X focus were actually moved; the fact that the X focus is on the top-level is invisible unless you use C code to query the X server directly.

### 用例 EXAMPLE

変数が設定される時､注目の巡回移動順序にのみ参加する窓を作る､その巡回移動順序中に､その前と後の部品に続く束縛を追加する｡ To make a window that only participates in the focus traversal ring when a variable is set, add the following bindings to the widgets before and after it in that focus ring:

    button .before -text "Before"
    button .middle -text "Middle"
    button .after  -text "After"
    checkbutton .flag -variable traverseToMiddle -takefocus 0
    pack .flag -side left
    pack .before .middle .after
    bind .before <Tab> {
       if {!$traverseToMiddle} {
          focus .after
          break
       }
    }
    bind .after <Shift-Tab> {
       if {!$traverseToMiddle} {
          focus .before
          break
       }
    }
    focus .before

### KEYWORDS

events, focus, keyboard, top-level, window manager
Copyright © 1990-1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.