beetlebug▾
/

text

Makes a text: a widget that shows and edits text of many lines, with tags, marks, images, and widgets.

text PATHNAME ?OPTION VALUE ...?

Description

Makes a text widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The content is lines of characters. Tags give ranges of the content a look and bindings, marks keep places that move with the edits, and image create and window create put images and widgets into the lines.

Many widget commands take an index of a place in the content. An index is a base with optional changes after it. The base is one of these forms:

A change is + N chars, - N chars, + N lines, - N lines, linestart, lineend, wordstart, or wordend, such as {1.0 lineend} or {end - 1 chars}. The units indices, displaychars, displayindices, and displaylines count places in other ways, and graphemes is an addition of ztk.

The tag sel is the selection, the mark insert is the insertion cursor, and the mark current follows the pointer. The parent of PATHNAME must exist, and PATHNAME must not. A text is a Text in CSS and for the option database.

Widget commands

CommandDescription
text bboxGives the box of the character at INDEX.
text compareCompares two indices.
text countCounts the characters, the lines, or other units between two indices.
text debugGives or sets the debug flag of the text widgets.
text deleteDeletes the content from INDEX1 up to INDEX2.
text dlineinfoGives the box of the display line of INDEX.
text dumpGives the text, the tags, the marks, the images, and the widgets of a range.
text editWorks on the undo stack and the modified flag.
text getGives the characters from INDEX1 up to INDEX2.
text imagePuts images into the content, and gives or sets their options.
text indexGives the LINE.CHAR form of an index.
text insertInserts text at INDEX, with optional tags.
text markWorks on the marks: names for places between characters.
text peerWorks on the peers of the text, in Tk.
text pendingsyncGives whether the layout of the lines has work to do.
text replaceReplaces the content from INDEX1 up to INDEX2 with new text.
text scanScrolls the text by a drag of the mouse.
text searchFinds a pattern in the content and gives the index of the first match.
text seeScrolls the text so that INDEX is visible.
text syncBrings the layout of the lines up to date.
text tagWorks on the tags: names for ranges of the content, with a look and bindings.
text windowPuts widgets into the content, and gives or sets their options.
text xviewReads or changes the horizontal view of the text.
text yviewReads or changes the vertical view of the text.
text cgetGives the value of an option of the text.
text configureGives or sets the options of the text.

Options

OptionTypeDefaultDatabase nameDescription
-autoseparatorsboolean1autoSeparatorsWhether the text adds undo separators by itself.
-backgroundcolor#ffffffbackgroundThe background color of the text.
-blockcursorboolean0blockCursorWhether the insertion cursor is a block.
-borderwidthscreen distance1borderWidthThe width of the border of the text.
-cursorcursor namextermcursorThe shape of the pointer over the text.
-endlineintegeremptyThe last line of the content that the text shows, in Tk.
-exportselectionboolean1exportSelectionWhether the selection of the text is also the selection of the application.
-fontfontTkFixedFontfontThe font of the text.
-foregroundcolor#000000foregroundThe color of the text.
-heightscreen distance24heightThe height of the text in lines of the font.
-highlightbackgroundcolor#d9d9d9highlightBackgroundThe color of the focus ring while the text has no focus, in the look of Tk on X11.
-highlightcolorcolor#000000highlightColorThe color of the focus ring while the text has the focus, in the look of Tk on X11.
-highlightthicknessscreen distance1highlightThicknessThe width of the focus ring, in the look of Tk on X11.
-inactiveselectbackgroundcolor#c3c3c3inactiveSelectBackgroundThe background color of the selection while the text has no focus.
-insertbackgroundcolor#000000insertBackgroundThe color of the insertion cursor.
-insertborderwidthscreen distance0insertBorderWidthThe width of the border of the insertion cursor.
-insertofftimeinteger300insertOffTimeThe time in milliseconds that the insertion cursor is hidden in each blink.
-insertontimeinteger600insertOnTimeThe time in milliseconds that the insertion cursor shows in each blink.
-insertunfocussedinsertunfocussednoneinsertUnfocussedHow the insertion cursor shows while the text has no focus.
-insertwidthscreen distance2insertWidthThe width of the insertion cursor.
-maxundointeger0maxUndoThe largest count of edits that the undo stack keeps.
-padxscreen distance1padXThe space at the left and the right of the content.
-padyscreen distance1padYThe space above and below the content.
-reliefreliefsunkenreliefThe 3-D look of the border.
-selectbackgroundcolor#c3c3c3selectBackgroundThe background color of the selected text.
-selectborderwidthscreen distance0selectBorderWidthThe width of the border around the selection.
-selectforegroundcolor#000000selectForegroundThe text color of the selected text.
-setgridboolean0setGridWhether the text sets a grid for the size of its toplevel.
-spacing1screen distance0spacing1The space above each line of the text.
-spacing2screen distance0spacing2The space between the display lines of a wrapped line.
-spacing3screen distance0spacing3The space below each line of the text.
-startlineintegeremptyThe first line of the content that the text shows, in Tk.
-statestatenormalstateWhether a script and the user can change the text.
-tabsstringemptytabsThe tab stops of the text.
-tabstyletabstyletabulartabStyleHow the text finds the tab stop of a tab character.
-takefocusstringemptytakeFocusWhether the Tab key can move the focus to the text.
-undoboolean0undoWhether the text keeps an undo stack.
-widthinteger80widthThe width of the text in average characters of the font.
-wrapwrapcharwrapHow the text breaks a line longer than its width.
-xscrollcommandscriptemptyxScrollCommandA command prefix that the text calls when its horizontal view changes.
-yscrollcommandscriptemptyyScrollCommandA command prefix that the text calls when its vertical view changes.

-autoseparators BOOLEAN

Whether the text adds undo separators by itself.

With -undo on and a true value, the text puts a separator in the undo stack at each change of the kind of edit, such as from typing to a deletion. With a false value, only edit separator adds separators.

% text .autoseparators -autoseparators 0
> .autoseparators cget -autoseparators
0
% text .autoseparators2 -autoseparators maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-background COLOR

The background color of the text.

The color behind the content. -bg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

text with -width 24 -height 3 and -background {#fde68a}-background {#fde68a}text with -width 24 -height 3 and -background {#bfdbfe}-background {#bfdbfe}
Each with -width 24 -height 3.
% text .background -background {#336699}
> .background cget -background
#336699
% text .background2 -background nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-blockcursor BOOLEAN

Whether the insertion cursor is a block.

In Tk, a true value draws the insertion cursor as a block over a character. ztk stores the value with no effect: the cursor is a bar.

% text .blockcursor -blockcursor 1
> .blockcursor cget -blockcursor
1
% text .blockcursor2 -blockcursor maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-borderwidth DISTANCE

The width of the border of the text.

The width of the border around the text. -bd is the same option. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

text with -width 24 -height 3 -relief solid and -borderwidth 0-borderwidth 0text with -width 24 -height 3 -relief solid and -borderwidth 1-borderwidth 1text with -width 24 -height 3 -relief solid and -borderwidth 4-borderwidth 4
Each with -width 24 -height 3 -relief solid.
% text .borderwidth -borderwidth 4
> .borderwidth cget -borderwidth
4
% text .borderwidth2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-cursor CURSOR

The shape of the pointer over the text.

A cursor name of Tk, such as hand2 or xterm. A value that starts with @ names a file. An empty value uses the cursor of the parent.

% text .cursor -cursor hand2
> .cursor cget -cursor
hand2
% text .cursor2 -cursor nocursor
bad cursor spec "nocursor"
-errorcode TK VALUE CURSOR

-endline LINE

The last line of the content that the text shows, in Tk.

In Tk, the text shows and gives only the lines up to this line of its content, for a peer. An empty value uses the last line. ztk stores the value with no effect.

% text .endline -endline 5
> .endline cget -endline
5
% text .endline2 -endline x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-exportselection BOOLEAN

Whether the selection of the text is also the selection of the application.

In Tk, a true value makes a selection in the text the PRIMARY selection, and selection get gives it. ztk stores the value with no effect: the selection of the text is not the PRIMARY selection.

% text .exportselection -exportselection 0
> .exportselection cget -exportselection
0
% text .exportselection2 -exportselection maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-font FONT

The font of the text.

A font name, such as TkDefaultFont, or a font description, such as {Helvetica 12 bold}. A family that does not exist falls back to a font of the system.

text with -width 24 -height 3 and -font TkDefaultFont-font TkDefaultFonttext with -width 24 -height 3 and -font TkFixedFont-font TkFixedFonttext with -width 24 -height 3 and -font {Helvetica 16 bold}-font {Helvetica 16 bold}
Each with -width 24 -height 3.
% text .font -font {Helvetica 12 bold}
> .font cget -font
Helvetica 12 bold
% text .font2 -font {Helvetica big}
expected integer but got "big"
-errorcode TCL VALUE NUMBER

-foreground COLOR

The color of the text.

The color of the text. -fg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

text with -width 24 -height 3 and -foreground {#b91c1c}-foreground {#b91c1c}text with -width 24 -height 3 and -foreground {#2563eb}-foreground {#2563eb}
Each with -width 24 -height 3.
% text .foreground -foreground {#336699}
> .foreground cget -foreground
#336699
% text .foreground2 -foreground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-height LINES

The height of the text in lines of the font.

The text asks for room for this count of lines of -font.

text with -width 24 and -height 2-height 2text with -width 24 and -height 4-height 4
Each with -width 24.
% text .height -height 4
> .height cget -height
4
% text .height2 -height x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-highlightbackground COLOR

The color of the focus ring while the text has no focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the text does not have the focus. ztk stores the value with no effect.

% text .highlightbackground -highlightbackground {#336699}
> .highlightbackground cget -highlightbackground
#336699
% text .highlightbackground2 -highlightbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-highlightcolor COLOR

The color of the focus ring while the text has the focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the text has the focus. ztk stores the value with no effect.

% text .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699
% text .highlightcolor2 -highlightcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-highlightthickness DISTANCE

The width of the focus ring, in the look of Tk on X11.

The width of the ring around the text that shows the focus. The modern theme draws the focus with the stylesheet.

% text .highlightthickness -highlightthickness 4
> .highlightthickness cget -highlightthickness
4
% text .highlightthickness2 -highlightthickness x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-inactiveselectbackground COLOR

The background color of the selection while the text has no focus.

An empty value hides the selection while the text has no focus.

% text .inactiveselectbackground -inactiveselectbackground {#336699}
> .inactiveselectbackground cget -inactiveselectbackground
#336699
% text .inactiveselectbackground2 -inactiveselectbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-insertbackground COLOR

The color of the insertion cursor.

The color of the bar that marks the place of the next typed character.

% text .insertbackground -insertbackground {#336699}
> .insertbackground cget -insertbackground
#336699
% text .insertbackground2 -insertbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-insertborderwidth DISTANCE

The width of the border of the insertion cursor.

In Tk, the insertion cursor can have a 3-D border of this width. ztk stores the value with no effect.

% text .insertborderwidth -insertborderwidth 4
> .insertborderwidth cget -insertborderwidth
4
% text .insertborderwidth2 -insertborderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-insertofftime N

The time in milliseconds that the insertion cursor is hidden in each blink.

0 stops the blink, and the cursor stays on.

% text .insertofftime -insertofftime 5
> .insertofftime cget -insertofftime
5
% text .insertofftime2 -insertofftime x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-insertontime N

The time in milliseconds that the insertion cursor shows in each blink.

The cursor blinks only while the text has the focus and -insertofftime is more than 0.

% text .insertontime -insertontime 5
> .insertontime cget -insertontime
5
% text .insertontime2 -insertontime x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-insertunfocussed WORD

How the insertion cursor shows while the text has no focus.

In Tk, none hides the cursor, hollow draws an outline, and solid draws the cursor as with the focus. ztk stores the value with no effect.

Values: hollow, none, solid.

% text .insertunfocussed -insertunfocussed hollow
> .insertunfocussed cget -insertunfocussed
hollow
% text .insertunfocussed2 -insertunfocussed bogus
bad insertunfocussed "bogus": must be hollow, none, or solid
-errorcode TCL LOOKUP INDEX insertunfocussed bogus

-insertwidth DISTANCE

The width of the insertion cursor.

A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

% text .insertwidth -insertwidth 4
> .insertwidth cget -insertwidth
4
% text .insertwidth2 -insertwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-maxundo N

The largest count of edits that the undo stack keeps.

0 or less keeps each edit. A separator ends one edit.

% text .maxundo -maxundo 5
> .maxundo cget -maxundo
5
% text .maxundo2 -maxundo x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-padx DISTANCE

The space at the left and the right of the content.

The space between the text and the left and the right sides. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

text with -width 24 -height 3 and -padx 1-padx 1text with -width 24 -height 3 and -padx 8-padx 8text with -width 24 -height 3 and -padx 16-padx 16
Each with -width 24 -height 3.
% text .padx -padx 4
> .padx cget -padx
4
% text .padx2 -padx x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-pady DISTANCE

The space above and below the content.

The space between the text and the top and the bottom. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

text with -width 24 -height 3 and -pady 1-pady 1text with -width 24 -height 3 and -pady 8-pady 8text with -width 24 -height 3 and -pady 16-pady 16
Each with -width 24 -height 3.
% text .pady -pady 4
> .pady cget -pady
4
% text .pady2 -pady x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-relief RELIEF

The 3-D look of the border.

The style of the border: raised and sunken look 3-D, and groove and ridge are lines. The theme draws the border, and the CSS of the theme can give a relief its own look with border-style.

Values: flat, groove, raised, ridge, solid, sunken.

text with -width 24 -height 3 -borderwidth 4 and -relief flat-relief flattext with -width 24 -height 3 -borderwidth 4 and -relief raised-relief raisedtext with -width 24 -height 3 -borderwidth 4 and -relief sunken-relief sunkentext with -width 24 -height 3 -borderwidth 4 and -relief groove-relief groovetext with -width 24 -height 3 -borderwidth 4 and -relief ridge-relief ridgetext with -width 24 -height 3 -borderwidth 4 and -relief solid-relief solid
Each with -width 24 -height 3 -borderwidth 4. The modern theme draws each relief but flat with the same border.
% text .relief -relief groove
> .relief cget -relief
groove
% text .relief2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy

-selectbackground COLOR

The background color of the selected text.

The color behind the characters of the selection. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

text with -width 24 -height 3 and -selectbackground {#fde68a}-selectbackground {#fde68a}text with -width 24 -height 3 and -selectbackground {#bfdbfe}-selectbackground {#bfdbfe}
Each with -width 24 -height 3.
% text .selectbackground -selectbackground {#336699}
> .selectbackground cget -selectbackground
#336699
% text .selectbackground2 -selectbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-selectborderwidth DISTANCE

The width of the border around the selection.

In Tk, the selection can have a 3-D border of this width. ztk stores the value with no effect.

% text .selectborderwidth -selectborderwidth 4
> .selectborderwidth cget -selectborderwidth
4
% text .selectborderwidth2 -selectborderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-selectforeground COLOR

The text color of the selected text.

The color of the characters of the selection.

text with -width 24 -height 3 and -selectforeground {#b91c1c}-selectforeground {#b91c1c}text with -width 24 -height 3 and -selectforeground {#2563eb}-selectforeground {#2563eb}
Each with -width 24 -height 3.
% text .selectforeground -selectforeground {#336699}
> .selectforeground cget -selectforeground
#336699
% text .selectforeground2 -selectforeground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-setgrid BOOLEAN

Whether the text sets a grid for the size of its toplevel.

In Tk, a true value makes the window manager resize the toplevel in steps of one line and one character. ztk stores the value with no effect.

% text .setgrid -setgrid 1
> .setgrid cget -setgrid
1
% text .setgrid2 -setgrid maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-spacing1 DISTANCE

The space above each line of the text.

The space above the first display line of each line of the text. A tag can set its own value.

text with -width 24 -height 3 and -spacing1 0-spacing1 0text with -width 24 -height 3 and -spacing1 8-spacing1 8
Each with -width 24 -height 3.
% text .spacing1 -spacing1 4
> .spacing1 cget -spacing1
4
% text .spacing12 -spacing1 x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-spacing2 DISTANCE

The space between the display lines of a wrapped line.

The space between two display lines of one line that wraps. A tag can set its own value.

% text .spacing2 -spacing2 4
> .spacing2 cget -spacing2
4
% text .spacing22 -spacing2 x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-spacing3 DISTANCE

The space below each line of the text.

The space below the last display line of each line of the text. A tag can set its own value.

% text .spacing3 -spacing3 4
> .spacing3 cget -spacing3
4
% text .spacing32 -spacing3 x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-startline LINE

The first line of the content that the text shows, in Tk.

In Tk, the text shows and gives only the lines from this line of its content, for a peer. An empty value uses the first line. ztk stores the value with no effect.

% text .startline -startline 2
> .startline cget -startline
2
% text .startline2 -startline x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-state STATE

Whether a script and the user can change the text.

disabled blocks insert, delete, replace, and the keys of the user, so the text is read only. normal allows each change.

Values: disabled, normal.

# A disabled text keeps its content.
% text .state -state disabled
> .state insert end abc
> .state get 1.0 end-1c
% text .state2 -state busy
bad state "busy": must be disabled or normal
-errorcode TCL LOOKUP INDEX state busy

-tabs LIST

The tab stops of the text.

A list of distances, each one with an optional alignment after it: left, right, center, or numeric. An empty value puts a tab stop at each 8 average characters.

% text .tabs -tabs {2c left 4c right}
> .tabs cget -tabs
2c left 4c right

ztk stores each value with no check. Tk 8.6.16 gives the error bad screen distance for a bad distance.

-tabstyle WORD

How the text finds the tab stop of a tab character.

In Tk, tabular gives each tab character of a line its own tab stop, and wordprocessor uses the next tab stop after the place of the tab character. ztk stores the value with no effect.

Values: tabular, wordprocessor.

% text .tabstyle -tabstyle wordprocessor
> .tabstyle cget -tabstyle
wordprocessor
% text .tabstyle2 -tabstyle bogus
bad tabstyle "bogus": must be tabular or wordprocessor
-errorcode TCL LOOKUP INDEX tabstyle bogus

-takefocus TEXT

Whether the Tab key can move the focus to the text.

1 puts the text in the order of the Tab key, and 0 leaves it out. An empty value uses the default rule of Tk for the widget. In Tk the value can also be a script, and its result is the answer. ztk stores each value with no check.

% text .takefocus -takefocus 1
> .takefocus cget -takefocus
1

ztk stores each value of the option with no check.

-undo BOOLEAN

Whether the text keeps an undo stack.

With a true value, each change goes on the undo stack, and edit undo and edit redo work.

% text .undo -undo 1
> .undo insert end hello
> .undo edit undo
> .undo get 1.0 end-1c
% text .undo2 -undo maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-width CHARS

The width of the text in average characters of the font.

The text asks for room for this count of characters of -font.

text with -height 3 and -width 12-width 12text with -height 3 and -width 24-width 24
Each with -height 3.
% text .width -width 5
> .width cget -width
5
% text .width2 -width x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-wrap WORD

How the text breaks a line longer than its width.

char breaks a line at any character, word breaks it at a space, and none breaks no line, so a long line goes past the right side.

Values: char, none, word.

text with -width 14 -height 4 and -wrap none-wrap nonetext with -width 14 -height 4 and -wrap char-wrap chartext with -width 14 -height 4 and -wrap word-wrap word
Each with -width 14 -height 4.
% text .wrap -wrap none
> .wrap cget -wrap
none
% text .wrap2 -wrap bogus
bad wrap "bogus": must be char, none, or word
-errorcode TCL LOOKUP INDEX wrap bogus

-xscrollcommand SCRIPT

A command prefix that the text calls when its horizontal view changes.

The text calls the prefix with two fractions, the first and the last visible part of the content, from 0 to 1. The usual value is {.sb set} for a scrollbar .sb.

% text .xscrollcommand -xscrollcommand {set ::done 1}
> .xscrollcommand cget -xscrollcommand
set ::done 1

ztk stores each value of the option with no check.

-yscrollcommand SCRIPT

A command prefix that the text calls when its vertical view changes.

The text calls the prefix with two fractions, the first and the last visible part of the content, from 0 to 1. The usual value is {.sb set} for a scrollbar .sb.

% text .yscrollcommand -yscrollcommand {set ::done 1}
> .yscrollcommand cget -yscrollcommand
set ::done 1

ztk stores each value of the option with no check.

Returns

PATHNAME.

Examples

% text .notes -width 40 -height 10
> .notes insert end "First line\nSecond line"
> .notes get 2.0 2.end
Second line

% text .styled
> .styled insert end "Warning: " bold "disk full"
> .styled tag configure bold -font {Helvetica 12 bold}
> .styled tag ranges bold
1.0 1.9

% winfo class [text .go]
Text

Errors

% text .x -foo 1
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo

% text .twice
> text .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS

# The parent .no does not exist.
% text .no.b
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no

% text
wrong # args: should be "text pathName ?-option value ...?"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also