MESSAGE IN TKINTER
In this tutorial, we are going to learn about the message widget in Tkinter and how we can use it followed by a workable example.
What is Message in Tkinter?
The Message widget in Tkinter is used to display the message to the user in regard to what’s happening inside the python GUI application. The messages displayed cannot be edited. The syntax for message is:
message_tk = Message( window, features )
Message features and properties are:
1 | anchor | It’s shows the initial position of text. It’s initial value is always the CENTER position which is used to position the text in the middle position. |
2 | bg | Displays the background color of the widget. |
3 | bitmap | It is used to display bitmap in the widget but if the image option is already given then this option will be ignored. |
4 | bd | It shows the width of the border. Same as borderwidth. |
5 | cursor | Shows the type of cursor when the mouse is hovered over the message. The default is a pointed arrow cursor. |
6 | font | Determines the type of font that is used for the message. |
7 | fg | Determines the foreground color of font that is used for the message. |
8 | height | Determines the height of the message widget. |
9 | image | You can use this feature when you want to use an image to be used in message widget. |
10 | justify | If the widget has more than one line then this feature is used to align text in RIGHT, LEFT or CENTER direction. |
11 | padx | Adds padding to the widget in horizontal direction. |
12 | pady | Adds padding to the widget in vertical direction. |
13 | relief | Gives border decoration like FLAT, SUNKEN, RAISED GROOVE and RIDGE. The default border type is FLAT. |
14 | text | This feature determines what will be mentioned as a message;
E.g. text=”Hello, Tkinter” will be used as a message. |
15 | textvariable | By using this feature, you can easily update the text of the message whenever you want. |
16 | underline | It is used with the text option to tell whether the character should be underlined. -1 is a default value (no underline). |
17 | width | Decides the width of the message. |
18 | wraplength | Decides when to wrap the label text into more than one lines. |
Creating Message Widget
You can create a simple message as follows:
from tkinter import * screen = Tk() screen.geometry('400x400') message_box = Message(screen, text="Hello, Tkinter!", relief=RIDGE) message_box.pack() screen.mainloop()
Output will be:
References have been used from here