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

10. The Label widget

Label widgets can display one or more lines of text in the same style, or a bitmap or image. To create a label widget in a root window or frame master:

    w = Label ( master, option, ... )

The constructor returns the label widget. Options include:

anchorThis options controls where the text is positioned if the widget has more space than the text needs. The default is anchor=CENTER, which centers the text in the available space. For other values, see Section 4.5, “Anchors”. For example, if you use anchor=NW, the text would be positioned in the upper left-hand corner of the available space.
bg or backgroundThe background color of the label area. See Section 4.3, “Colors”.
bitmapSet this option equal to a bitmap or image object and the label will display that graphic. See Section 4.7, “Bitmaps” and Section 4.9, “Images”.
bd or borderwidthWidth of the border around the label. Default is 2.
cursorCursor that appears when the mouse is over this label. See Section 4.8, “Cursors”.
fontIf you are displaying text in this label (with the text or textvariable option, the font option specifies in what font that text will be displayed. See Section 4.4, “Type fonts”.
fg or foregroundIf you are displaying text or a bitmap in this label, this option specifies the color of the text. If you are displaying a bitmap, this is the color that will appear at the position of the 1-bits in the bitmap. See Section 4.3, “Colors”.
heightHeight of the label in lines (not pixels!). If this option is not set, the label will be sized to fit its contents.
imageTo display a static image in the label widget, set this option to an image object. See Section 4.9, “Images”.
justifySpecifies how multiple lines of text will be aligned with respect to each other: LEFT for flush left, CENTER for centered (the default), or RIGHT for right-justified.
padxExtra space added to the left and right of the text within the widget. Default is 1.
padyExtra space added above and below the text within the widget. Default is 1.
reliefSpecifies the appearance of a decorative border around the label. The default is FLAT; for other values, see Section 4.6, “Relief styles”.
takefocusNormally, focus does not cycle through Label widgets; see Section 23, “Focus: routing keyboard input”. If you want this widget to be visited by the focus, set takefocus=1.
textTo display one or more lines of text in a label widget, set this option to a string containing the text. Internal newlines ("\n") will force a line break.
textvariableTo slave the text displayed in a label widget to a control variable of class StringVar, set this option to that variable. SeeSection 22, “Control variables: the values behind the widgets”.
underlineYou can display an underline (_) below the nth letter of the text, counting from 0, by setting this option to n. The default is underline=-1, which means no underlining.
widthWidth of the label in characters (not pixels!). If this option is not set, the label will be sized to fit its contents.
wraplengthYou can limit the number of characters in each line by setting this option to the desired number. The default value, 0, means that lines will be broken only at newlines.

There are no special methods for label widgets other than the common ones (see Section 19, “Universal widget methods”).