Next / Previous / Contents / TCC Help System / NM Tech homepage

7.14. Canvas text objects

You can display one or more lines of text on a canvas C by creating a text object:

    id = C.create_text ( x, y, option, ... )

This returns the object ID of the text object on canvas C. Options include:

activefill The text color to be used when the text is active, that is, when the mouse is over it. For option values, see fill below.
activestipple The stipple pattern to be used when the text is active. For option values, see stipple below.
anchor The default is anchor=CENTER, meaning that the text is centered vertically and horizontally around position (x, y). See Section 5.5, “Anchors” for possible values. For example, if you specify anchor=SW, the text will be positioned so its lower left corner is at point (x, y).
disabledfill The text color to be used when the text object's state is DISABLED. For option values, see fill below.
disabledstipple The stipple pattern to be used when the text is disabled. For option values, see stipple below.
fill The default text color is black, but you can render it in any color by setting the fill option to that color. See Section 5.3, “Colors”.
font If you don't like the default font, set this option to any font value. See Section 5.4, “Type fonts”.
justify For multi-line textual displays, this option controls how the lines are justified: LEFT (the default), CENTER, or RIGHT.
offset The stipple offset to be used in rendering the text. For more information, see Section 5.14, “Matching stipple patterns”.
state By default, the text item's state is NORMAL. Set this option to DISABLED to make in unresponsive to mouse events, or set it to HIDDEN to make it invisible.
stipple A bitmap indicating how the text will be stippled. Default is stipple="", which means solid. A typical value would be stipple="gray25". See Section 5.7, “Bitmaps”.
tags The tags to be associated with the object, as a sequence of strings. See Section 7.4, “Canvas tags”.
text The text to be displayed in the object, as a string. Use newline characters ("\n") to force line breaks.
width If you don't specify a width option, the text will be set inside a rectangle as long as the longest line. However, you can also set the width option to a dimension, and each line of the text will be broken into shorter lines, if necessary, or even broken within words, to fit within the specified width. See Section 5.1, “Dimensions”.

You can change the text displayed in a text item.

A number of canvas methods allow you to manipulate text items. See Section 7.6, “Methods on Canvas widgets”, especially dchars, focus, icursor, index, and insert.