IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
20.1.6.8 The index Parameter

20.1.6.8 The index Parameter

A number of widgets require``index'' parameters to be passed. These are used to point at a specific place in a Text widget, or to particular characters in an Entry widget, or to particular menu items in a Menu widget.

Entry widget indexes (index, view index, etc.)
Entry widgets have options that refer to character positions in the text being displayed. You can use these Tkinter functions to access these special points in text widgets:

AtEnd()
refers to the last position in the text

AtInsert()
refers to the point where the text cursor is

AtSelFirst()
indicates the beginning point of the selected text

AtSelLast()
denotes the last point of the selected text and finally

At(x[, y])
refers to the character at pixel location x, y (with y not used in the case of a text entry widget, which contains a single line of text).

Text widget indexes
The index notation for Text widgets is very rich and is best described in the Tk man pages.

Menu indexes (menu.invoke(), menu.entryconfig(), etc.)

Some options and methods for menus manipulate specific menu entries. Anytime a menu index is needed for an option or a parameter, you may pass in:

  • an integer which refers to the numeric position of the entry in the widget, counted from the top, starting with 0;
  • the string 'active', which refers to the menu position that is currently under the cursor;
  • the string "last" which refers to the last menu item;
  • An integer preceded by @, as in @6, where the integer is interpreted as a y pixel coordinate in the menu's coordinate system;
  • the string "none", which indicates no menu entry at all, most often used with menu.activate() to deactivate all entries, and finally,
  • a text string that is pattern matched against the label of the menu entry, as scanned from the top of the menu to the bottom. Note that this index type is considered after all the others, which means that matches for menu items labelled last, active, or none may be interpreted as the above literals, instead.

See About this document... for information on suggesting changes.