back next

The Tkinter Message Widget

The Message widget is a variant of the Label, designed to display multiline messages. The message widget can wrap text, and adjust its width to maintain a given aspect ratio.

When to use the Message Widget

The widget can be used to display short text messages, using a single font. You can often use a plain Label instead. If you need to display text in multiple fonts, use a Text widget.

Patterns #

To create a message, all you have to do is to pass in a text string. The widget will automatically break the lines, if necessary.

from Tkinter import *

master = Tk()

w = Message(master, text="this is a message")


If you don’t specify anything else, the widget attepts to format the text to keep a given aspect ratio. If you don’t want that behaviour, you can specify a width:

w = Message(master, text="this is a relatively long message", width=50)

Reference #

Message(master=None, **options) (class) [#]

A multi-line text message.

Parent widget.
Widget options. See the description of the config method for a list of available options.

config(**options) [#]

Modifies one or more widget options. If no options are given, the method returns a dictionary containing all current option values.

Widget options.
Where in the message widget the text should be placed. Use one of N, NE, E, SE, S, SW, W, NW, or CENTER. Default is CENTER. (the database name is anchor, the class is Anchor)
Aspect ratio, given as the width/height relation in percent. The default is 150, which means that the message will be 50% wider than it is high. Note that if the width is explicitly set, this option is ignored. (aspect/Aspect)
Message background color. The default value is system specific. (background/Background)
Same as background.
Border width. Default value is 2. (borderWidth/BorderWidth)
Same as borderwidth.
What cursor to show when the mouse is moved over the message widget. The default is to use the standard cursor. (cursor/Cursor)
Message font. The default value is system specific. (font/Font)
Text color. The default value is system specific. (foreground/Foreground)
Same as foreground.
Together with highlightcolor and highlightthickness, this option controls how to draw the highlight region. (highlightBackground/HighlightBackground)
See highlightbackground. (highlightColor/HighlightColor)
See highlightbackground. (highlightThickness/HighlightThickness)
Defines how to align multiple lines of text. Use LEFT, RIGHT, or CENTER. Note that to position the text inside the widget, use the anchor option. Default is LEFT. (justify/Justify)
Horizontal padding. Default is -1 (no padding). (padX/Pad)
Vertical padding. Default is -1 (no padding). (padY/Pad)
Border decoration. The default is FLAT. Other possible values are SUNKEN, RAISED, GROOVE, and RIDGE. (relief/Relief)
If true, the widget accepts input focus. The default is false. (takeFocus/TakeFocus)
Message text. The widget inserts line breaks if necessary to get the requested aspect ratio. (text/Text)
Associates a Tkinter variable (usually a StringVar) with the message. If the variable is changed, the message text is updated. (textVariable/Variable)
Widget width, in character units. If omitted, the widget picks a suitable width based on the aspect setting. (width/Width)


A Django site. rendered by a django application. hosted by webfaction.