Python Tkinter Message

python tutorials and learn python

Created with Sketch.

Python Tkinter Message

The Message widget is used to show the message to the user regarding the behaviour of the python application. The message widget shows the text messages to the user which can not be edited.

The message text contains more than one line. However, the message can only be shown in the single font.

The syntax to use the Message widget is given below.

Syntax

  1. w = Message(parent, options)

A list of possible options is given below.

SNOptionDescription
1anchorIt is used to decide the exact position of the text within the space provided to the widget if the widget contains more space than the need of the text. The default is CENTER.
2bgThe background color of the widget.
3bitmapIt is used to display the graphics on the widget. It can be set to any graphical or image object.
4bdIt represents the size of the border in the pixel. The default size is 2 pixel.
5cursorThe mouse pointer is changed to the specified cursor type. The cursor type can be an arrow, dot, etc.
6fontThe font type of the widget text.
7fgThe font color of the widget text.
8heightThe vertical dimension of the message.
9imageWe can set this option to a static image to show that onto the widget.
10justifyThis option is used to specify the alignment of multiple line of code with respect to each other. The possible values can be LEFT (left alignment), CENTER (default), and RIGHT (right alignment).
11padxThe horizontal padding of the widget.
12padyThe vertical padding of the widget.
13reliefIt represents the type of the border. The default type is FLAT.
14textWe can set this option to the string so that the widget can represent the specified text.
15textvariableThis is used to control the text represented by the widget. The textvariable can be set to the text that is shown in the widget.
16underlineThe default value of this option is -1 that represents no underline. We can set this option to an existing number to specify that nth letter of the string will be underlined.
17widthIt specifies the horizontal dimension of the widget in the number of characters (not pixel).
18wraplengthWe can wrap the text to the number of lines by setting this option to the desired number so that each line contains only that number of characters.

Example

  1. from tkinter import *
  2. top = Tk()
  3. top.geometry(“100×100”)
  4. var = StringVar()
  5. msg = Message( top, text = “Welcome to Javatpoint”)
  6. msg.pack()
  7. top.mainloop()

Output:

Python Tkinter Message

 

Leave a Reply

Your email address will not be published. Required fields are marked *