beetlebug▾
/

message

Makes a message: a widget that shows a text of more than one line.

message PATHNAME ?OPTION VALUE ...?

Description

Makes a message widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. A message shows a text and breaks it into lines at spaces. With -width 0, the ratio of -aspect sets the length of the lines. A message runs no script.

The parent of PATHNAME must exist, and PATHNAME must not. A message is a Message in CSS and for the option database, and ztk::class gives it a style class for a stylesheet.

Widget commands

CommandDescription
message cgetGives the value of an option of the message.
message configureGives or sets the options of the message.

Options

OptionTypeDefaultDatabase nameDescription
-anchoranchorcenteranchorThe place of the content in a message larger than it.
-aspectinteger150aspectThe ratio of the width to the height of the text, in percent.
-backgroundcolor#d9d9d9backgroundThe background color of the message.
-borderwidthscreen distance0borderWidthThe width of the border of the message.
-cursorcursor nameemptycursorThe shape of the pointer over the message.
-fontfontTkDefaultFontfontThe font of the text.
-foregroundcolor#000000foregroundThe color of the text.
-highlightbackgroundcolor#d9d9d9highlightBackgroundThe color of the focus ring while the message has no focus, in the look of Tk on X11.
-highlightcolorcolor#000000highlightColorThe color of the focus ring while the message has the focus, in the look of Tk on X11.
-highlightthicknessscreen distance0highlightThicknessThe width of the focus ring, in the look of Tk on X11.
-justifyjustificationleftjustifyThe alignment of the lines of the text.
-padxscreen distance-1padXThe space at the left and the right of the content.
-padyscreen distance-1padYThe space above and below the content.
-reliefreliefflatreliefThe 3-D look of the border.
-takefocusstring0takeFocusWhether the Tab key can move the focus to the message.
-textstringemptytextThe text of the message.
-textvariablevariable nameemptytextVariableA global variable whose value is the text of the message.
-widthscreen distance0widthThe length of the lines of the text.

-anchor ANCHOR

The place of the content in a message larger than it.

When the message is larger than its text, the anchor puts the text at that side or corner. center puts it in the middle.

Values: n, ne, e, se, s, sw, w, nw, center.

% message .anchor -anchor w
> .anchor cget -anchor
w
% message .anchor2 -anchor middle
bad anchor "middle": must be n, ne, e, se, s, sw, w, nw, or center
-errorcode TCL LOOKUP INDEX anchor middle

-aspect PERCENT

The ratio of the width to the height of the text, in percent.

With -width 0, the message breaks its text into lines so that 100 times the width divided by the height is near this value. 150 makes the text one and a half times as wide as it is tall.

message with -text A note that is long enough to wrap and -aspect 50-aspect 50message with -text A note that is long enough to wrap and -aspect 150-aspect 150message with -text A note that is long enough to wrap and -aspect 400-aspect 400
Each with -text A note that is long enough to wrap.
# A larger aspect gives a wider message.
% message .aspect -text "one two three four five six seven eight"
> message .aspectwide -text "one two three four five six seven eight" -aspect 400
> expr {[winfo reqwidth .aspectwide] > [winfo reqwidth .aspect]}
1
% message .aspect2 -aspect x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-background COLOR

The background color of the message.

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

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

-borderwidth DISTANCE

The width of the border of the message.

The width of the border around the message. -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.

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

-cursor CURSOR

The shape of the pointer over the message.

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.

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

-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.

message with -text Note and -font TkDefaultFont-font TkDefaultFontmessage with -text Note and -font TkFixedFont-font TkFixedFontmessage with -text Note and -font {Helvetica 16 bold}-font {Helvetica 16 bold}
Each with -text Note.
% message .font -font {Helvetica 12 bold}
> .font cget -font
Helvetica 12 bold
% message .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.

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

-highlightbackground COLOR

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

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

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

-highlightcolor COLOR

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

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

% message .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699
% message .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 message that shows the focus. The modern theme draws the focus with the stylesheet.

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

-justify SIDE

The alignment of the lines of the text.

How the lines of the text line up with each other: at the left, in the middle, or at the right.

Values: left, right, center.

message with -text Short
A longer line and -justify left-justify leftmessage with -text Short
A longer line and -justify center-justify centermessage with -text Short
A longer line and -justify right-justify right
Each with -text Short A longer line.
% message .justify -justify right
> .justify cget -justify
right
% message .justify2 -justify middle
bad justification "middle": must be left, right, or center
-errorcode TCL LOOKUP INDEX justification middle

-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. The default -1 leaves the padding to the theme, and a value of the script replaces it.

message with -text Note and -padx 1-padx 1message with -text Note and -padx 4-padx 4message with -text Note and -padx 16-padx 16
Each with -text Note.
% message .padx -padx 4
> .padx cget -padx
4
% message .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. The default -1 leaves the padding to the theme, and a value of the script replaces it.

message with -text Note and -pady 1-pady 1message with -text Note and -pady 2-pady 2message with -text Note and -pady 10-pady 10
Each with -text Note.
% message .pady -pady 4
> .pady cget -pady
4
% message .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.

message with -text Note -borderwidth 4 and -relief flat-relief flatmessage with -text Note -borderwidth 4 and -relief raised-relief raisedmessage with -text Note -borderwidth 4 and -relief sunken-relief sunkenmessage with -text Note -borderwidth 4 and -relief groove-relief groovemessage with -text Note -borderwidth 4 and -relief ridge-relief ridgemessage with -text Note -borderwidth 4 and -relief solid-relief solid
Each with -text Note -borderwidth 4.
% message .relief -relief groove
> .relief cget -relief
groove
% message .relief2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy

-takefocus TEXT

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

1 puts the message 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.

% message .takefocus -takefocus 1
> .takefocus cget -takefocus
1

ztk stores each value of the option with no check.

-text TEXT

The text of the message.

The text that the message shows. The message breaks the text at spaces into lines, and a newline starts a new line.

message with -text Note-text Notemessage with -text {A longer note}-text {A longer note}
% message .text -text Save
> .text cget -text
Save

Each string is a valid text.

-textvariable VAR

A global variable whose value is the text of the message.

The message shows the value of the global variable VAR, and changes its text when the variable changes.

% message .textvariable -textvariable v
> .textvariable cget -textvariable
v

Each name is a valid variable name.

-width DISTANCE

The length of the lines of the text.

With a value more than 0, the message breaks its text into lines of at most this length, and -aspect has no effect. 0 uses -aspect.

message with -text A note that is long enough to wrap and -width 0-width 0message with -text A note that is long enough to wrap and -width 60-width 60message with -text A note that is long enough to wrap and -width 120-width 120
Each with -text A note that is long enough to wrap.
% message .width -text "one two three four five six" -width 60
> update
> winfo reqwidth .width
60
% message .width2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELS

Returns

PATHNAME.

Examples

% message .note -text "The file has changes that are not saved. Save them before you close the window?"
> .note cget -aspect
150

% winfo class [message .go]
Message

Errors

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

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

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

% message
wrong # args: should be "message 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