Tk - Message Widget


Advertisements

A message widget is used for displaying multiple lines of text. The syntax for message widget is shown below −

message messageName options

Options

The options available for the message widget are listed below in the following table −

Sr.No. Syntax & Description
1

-background color

Used to set background color for widget.

2

-borderwidth width

Used to draw with border in 3D effects.

3

-font fontDescriptor

Used to set font for widget.

4

-foreground color

Used to set foreground color for widget.

5

-padx number

Sets the padx for the widget.

6

-pady number

Sets the pady for the widget.

7

-relief condition

Sets the 3D relief for this widget. The condition may be raised, sunken, flat, ridge, solid, or groove.

8

-text text

Sets the text for the widget.

9

-textvariable varName

Variable associated with the widget. When the text of widget changes, the variable is set to text of widget.

10

-justify alignment

Sets the alignment of text, which can be left, center, or right.

11

-aspect ratio

Sets the aspect ratio in percent. The default is 150. It is available when width option is not used.

12

-width number

Sets the width for widget.

A simple example for message widget is shown below −

#!/usr/bin/wish

grid [message .myMessage -background red -foreground white -text "Hello\nWorld" -relief
   ridge -borderwidth 8 -padx 10 -pady 10 -font {Helvetica -18 bold} -textvariable
   myvariable -justify right -aspect 100 ]

When we run the above program, we will get the following output −

Message Example
tk_basic_widgets.htm
Advertisements