Tkinter Message Tutorial
Message in Widget control mainly allows to display short messages, which are similar to Label, but more flexible to use, with automatic branching. For some short messages that you don’t want to do further editing, you can use Message to display them.
The construction method of Message is as follows.
Message(master, options)
The first argument to the Message( ) method is the parent object, indicating which parent object this tag will be built inside. The following are other commonly used options parameters within the Message( ) method.
(1) anchor
: controls the position of the message if there is more space than needed, the default is CENTER.
(2) aspect
: control width to height ratio, default is 150%.
(3)bg or background
: background color.
(4)bitmap
: use default bitmap as Message content.
(5) cursor
: the shape of the Message when the mouse cursor is over it.
(6) fg or foreground
: the font color.
(7) font
: selectable font, font style and size.
(8) height
: the height of Message, in characters.
(9) image
: the Message is rendered as an image.
(10) justify
: the alignment method when there are multiple lines of text, the value is LEFT/CENTER/RIGHT (left/center/right), the default is center alignment.
(11) padx/pady
: the spacing between Message text and border, in pixels.
(12) relief
: the default is RELIEF=FLAT, which can control the text outer frame.
(13) text
: Message content, if there is "\n" then you can input multiple lines of text.
(14) textvariable
: you can set Message to be displayed in a variable way.
(15) underline
: you can set the first text with underline, starting from 0, the default is -1, which means no underline.
(16) width
: the width of the Message, in characters.
(17) wraplength
: text in how much width after the line break, the unit is pixels.
Tkinter Message Tutorial Example#1
The basic usage of Message.
from tkinter import *
root = Tk()
root.title("apidemos.com")
myText = """apidemos.com provides tutorials on the basics of programming, introducing the basics of various programming languages such as HTML, CSS, Javascript, Python, Java, Ruby, C, PHP , MySQL and more. The site also provides a large number of online examples, through the examples, you can better learn programming..."""
msg = Message(root,bg="yellow",text=myText,
font="times 30 italic")
msg.pack(padx=10,pady=10)
root.mainloop()
Output: