An Introduction to Tkinter
前页 | Chapter 42. The Text Widget | 后页

# Options

The `Text` widget supports the following options.

FIXME: sort in relevance order

Table 42-5. Text Options

Option | Type | Description
--- | --- | ---
`background (bg)` | color | The background color for this widget. Default is system specific (usually "white"). If you change the background color, you should make sure to change the foreground color as well.
`borderwidth (bd)` | distance | Border width. Default is platform dependent, but is usually one or two pixels.
`cursor` | cursor | The cursor to show when the mouse pointer is placed over the text widget. The default is a text insertion cursor (typically an "I beam" cursor, such as `xterm`).
`exportselection` | flag | If true, selected text is automatically exported to the clipboard. Default is true.
`font` | font | Widget font. The default is system specific (usually "black").
`foreground (fg)` | color | Text color.
`height` | distance | Widget height, in text units.
`highlightbackground, highlightcolor` | color | Controls how to draw the focus highlight border. When the widget has focus, the border is drawn in the `highlightcolor` color. Otherwise, it is drawn in the `highlightbackground` color. The defaults are system specific.
`highlightthickness` | distance | Controls the width of the focus highlight border. Default is 0 (no border).
`insertbackground` | color |
`insertborderwidth` | distance |
`insertofftime, insertontime` | time |
`insertwidth` | distance | Controls cursor blinking and style. It's usually best to leave these as they are.
`padx, pady` | distance | Extra padding between the widget's inner border and the text body. Default is 0 (no padding).
`relief` | constant | Border decoration. The default is `SUNKEN`. Other possible values are `FLAT`, `RAISED`, `GROOVE`, and `RIDGE`.
`selectbackground` | color | Selection background color. The default is system and display specific.
`selectborderwidth` | distance | Selection border width. The default is system specific.
`selectforeground` | color | Selection text color. The default is system and display specific.
`setgrid` | flag | If true, Tkinter attempts to resize the window containing the text widget in full character steps (based on the `font` option).
`spacing1` | distance | Spacing to use above the first line in a block of text. Default is 0 (no extra spacing).
`spacing2` | distance | Spacing to use between the lines in a block of text wrapped by the widget. Default is 0 (no extra spacing).
`spacing3` | distance | Spacing to use after the last line of text in a block of text having this tag. Default is 0 (no extra spacing).
`state` | constant | One of `NORMAL` or `DISABLED`. Default is `NORMAL`. Note that if you set this to `DISABLED`, calls to `insert` or `delete` are ignored.
`tabs` | string |
`takefocus` | flag | If true, you can use Tab to move focus to this widget (but not from it; the default bindings for the `Text` widget insert the tab character). Default is an empty string, which means that the text widget accepts focus only if it has any keyboard bindings (default is on, in other words).
`width` | distance | Widget width, in text units.
`wrap` | constant | Word wrap mode. Use one of `NONE`, `CHAR`, or `WORD`. Default is `NONE`.
`xscrollcommand, yscrollcommand` | callback | Scrollbar callbacks. These options should be set to the `set` method for the corresponding scrollbar.

前页 | Home | 后页
Methods | Up | The Toplevel Widget