Python tkinter Message

A message is similar to a label.But messages are generally used to display multiple lines of text where as a label is used to display a single line of text.

tkinter message

All the text in the message will be displayed using the same font. To create a message, we need to create an object of Message class as:

m = Message(f, text='This is a message that has more than one line of text.', width=200, font=('Roman', 20, 'bold italic'), fg='dark goldenrod')

Here, 'text' represents the text to be displayed in the message. The 'width' option specifies the message width in pixels.'font' represents the font for the message. We can use options 'fg' for specifying foreground color and 'bg' for specifying background color for the message text.

tkinter message example

CopiedCopy Code

from tkinter import * 
class MyMessage: 
   def __init__(self, root): 
      self.f = Frame(root, height=350, width=500) 
      self.f.propagate(0) 
      self.f.pack() 
      self.m = Message(self.f, text='This is a message that has more than one line of text.', width=200, font=('Roman', 20, 'bold italic'), fg='dark goldenrod')     
      self.m.pack(side=LEFT)
root = Tk() 
mb = MyMessage(root) 
root.mainloop()