text tag
Works on the tags: names for ranges of the content, with a look and bindings.
PATHNAME tag add TAG INDEX1 ?INDEX2 ...?
PATHNAME tag bind TAG ?SEQUENCE? ?SCRIPT?
PATHNAME tag cget TAG OPTION
PATHNAME tag configure TAG ?OPTION? ?VALUE? ?OPTION VALUE ...?
PATHNAME tag delete TAG ?TAG ...?
PATHNAME tag lower TAG ?BELOW?
PATHNAME tag names ?INDEX?
PATHNAME tag nextrange TAG INDEX1 ?INDEX2?
PATHNAME tag prevrange TAG INDEX1 ?INDEX2?
PATHNAME tag raise TAG ?ABOVE?
PATHNAME tag ranges TAG
PATHNAME tag remove TAG INDEX1 ?INDEX2 ...?
Description
A tag marks ranges of characters. The options of a tag change the look of its characters, and a tag with a higher priority wins over a lower tag. The forms are:
addandremove: add the tag to the ranges from each INDEX1 up to INDEX2, or remove it.bind: binds SCRIPT to an event on the characters of the tag, asbinddoes for a widget.cgetandconfigure: give or set the options of the tag.delete: removes each TAG, its options, and its bindings.lowerandraise: change the priority of TAG.names: gives each tag in the order of priority, or the tags of the character at INDEX.nextrangeandprevrange: give the first range of the tag after INDEX1, or the last range before INDEX1.ranges: gives the start and the end of each range of the tag.
The options of a tag are -background, -foreground, -font, -justify, -lmargin1, -lmargin2, -lmargincolor, -rmargin, -rmargincolor, -offset, -overstrike, -overstrikefg, -underline, -underlinefg, -relief, -borderwidth, -spacing1, -spacing2, -spacing3, -tabs, -tabstyle, -wrap, -elide, -selectbackground, -selectforeground, -bgstipple, and -fgstipple. The tag sel is the selection.
Returns
A list for names, ranges, nextrange, and prevrange, the value for cget, else an empty string.
Examples
% text .tg
> .tg insert end "hello world"
> .tg tag add hi 1.0 1.5
> .tg tag configure hi -foreground red
> list [.tg tag ranges hi] [.tg tag cget hi -foreground]
{1.0 1.5} red
% text .tg2
> .tg2 insert end abc
> .tg2 tag add x 1.0 1.2
> .tg2 tag remove x 1.0 1.1
> .tg2 tag ranges x
1.1 1.2
Errors
% text .tg3; .tg3 tag bogus
bad tag option "bogus": must be add, bind, cget, configure, delete, lower, names, nextrange, prevrange, raise, ranges, or remove
-errorcode NONE
% text .tg4; .tg4 tag cget nosuch -foreground
tag "nosuch" isn't defined in text widget
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1