Python Tkinter Message Widget
The Message widget in Tkinter is used to display text that users cannot edit. It is useful when a Python application needs to show information, instructions, notifications, or descriptions.
Unlike the Label widget, the Message widget is designed to work with longer text and can automatically wrap the content according to the specified width.
Table of Contents

Complete Advance AI Topics: Click Here
SQL Tutorial: Click Here
Features of the Message Widget
The Tkinter Message widget provides several useful features:
- Displays multi-line text.
- Automatically wraps text within a specified width.
- Supports customization options such as font, color, and alignment.
- Useful for displaying instructions, notifications, and descriptions in an application.
Syntax
w = Message(parent, options)
Tkinter Message Widget Options
The following table describes commonly used options of the Tkinter Message widget:
| SN | Option | Description |
|---|---|---|
| 1 | anchor | Specifies the position of the text inside the widget when additional space is available. The default value is CENTER. |
| 2 | bg | Sets the background color of the widget. |
| 3 | bitmap | Displays a graphical or image object inside the widget. |
| 4 | bd | Defines the border size in pixels. The default value is 2. |
| 5 | cursor | Changes the cursor appearance when it is placed over the widget, such as an arrow or dot. |
| 6 | font | Specifies the font style used for the text. |
| 7 | fg | Sets the color of the text. |
| 8 | height | Defines the vertical size of the message widget. |
| 9 | image | Displays a static image inside the widget. |
| 10 | justify | Controls the alignment of multi-line text. Available values include LEFT, CENTER, and RIGHT. The default is CENTER. |
| 11 | padx | Sets horizontal padding around the content. |
| 12 | pady | Sets vertical padding around the content. |
| 13 | relief | Defines the border appearance, such as FLAT, RAISED, or SUNKEN. The default is FLAT. |
| 14 | text | Specifies the text displayed by the widget. |
| 15 | textvariable | Allows the displayed text to be controlled dynamically using a Tkinter variable. |
| 16 | underline | Specifies which character should be underlined. The default value is -1, meaning no character is underlined. |
| 17 | width | Sets the width of the widget in characters rather than pixels. |
| 18 | wraplength | Controls how the text is wrapped within the specified length. |
Example Usage of Tkinter Message Widget
Here is a simple example showing how to create a Message widget using Tkinter:
from tkinter import *
top = Tk()
top.geometry("250x150")
var = StringVar()
msg = Message(
top,
text="Welcome to UpdateGadh! Explore Python Tkinter.",
width=200,
font=("Arial", 12),
fg="blue"
)
msg.pack()
top.mainloop()
Output
When the program runs, a small window appears containing the specified message. The text is wrapped within a width of 200 pixels, uses the Arial font, and is displayed in blue.
When to Use the Message Widget?
The Message widget can be useful in the following situations:
- When you need to display static, multi-line text in a Tkinter application.
- When long text needs to be formatted and wrapped.
- When you need a simple alternative to the Label widget for displaying instructions or descriptions.
Download New Real Time Projects :- Click here
Conclusion
The Tkinter Message widget is a useful component for displaying non-editable text within a Python application. Its different customization options make it possible to present information in a clear and structured way.
Whether you want to display instructions, descriptions, or simple notifications, the Message widget can be a useful addition to your Tkinter project.
Start using the Tkinter Message widget in your Python projects and improve the way informative messages are displayed to users.
Stay tuned for more insightful Python tutorials!
SEO Keywords
python tkinter messagebox example, python message box without tkinter, tkinter messagebox options, python message box popup, tkinter messagebox custom buttons, module ‘tkinter’ has no attribute ‘messagebox’, python tkinter message, python tkinter messagebox, python tkinter messagebox example, python tkinter messagebox options, python tkinter messagebox yes no, python tkinter message box with entry, python tkinter messagebox size, python tkinter messagebox timeout, custom tkinter message box, python tkinter message example