In this video I’ll show you how to use the Message Widget to format blocks of text with multiple lines for Tkinter and Python.

Usually we use a Label widget for text. But if you have large blocks of text that will span multiple lines, you should consider using the Message Widget.

With the Message Widget, you can have multiple lines of text, choose how you want it justified (Left justify, Right justify, or Center justify), and also change the aspect ration of the the entire block of text.

Python Code: messages.py
(Github Code)

from tkinter import *

root = Tk()
root.title('Codemy.com - Message Widget!')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("400x900")

def change():
	my_message.config(text="And now for something completely different!",
		aspect=200)

# First one
frame1 = LabelFrame(root, text="Right Justified")
frame1.pack(pady=20)

my_message = Message(frame1, text="This is some long text that I am typing so that we can look at it, isn't it cool!?",
	font=("helvetica", 18),
	aspect=150,
	justify=RIGHT)
my_message.pack(pady=10, padx=10)

# Second One
frame2 = LabelFrame(root, text="Left Justified")
frame2.pack(pady=20)

my_message2 = Message(frame2, text="This is some long text that I am typing so that we can look at it, isn't it cool!?",
	font=("helvetica", 18),
	aspect=100,
	justify=LEFT)
my_message2.pack(pady=10, padx=10)

# Third One
frame3 = LabelFrame(root, text="Center Justified")
frame3.pack(pady=20)

my_message3 = Message(frame3, text="This is some long text that I am typing so that we can look at it, isn't it cool!?",
	font=("helvetica", 18),
	aspect=200,
	justify=CENTER)
my_message3.pack(pady=10, padx=10)

# Button
my_button = Button(root, text="Change Text", command=change)
my_button.pack(pady=20)

root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

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

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...