How to set justification on Tkinter Text box?

The Text widget supports multiline user input from the user. We can configure the Text widget properties such as its font properties, text color, background, etc., by using the configure() method.

To set the justification of our text inside the Text widget, we can use tag_add() and tag_configure() properties. We will specify the value of "justify" as CENTER.


# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame or window

# Set the size of the tkinter window

# Create a text widget
text=Text(win, width=40, height=10)

# justify the text alignment to the center
text.tag_configure("center", justify='center')
text.insert(INSERT, "Welcome to Tutorialspoint...")

# Add the tag from start to end text
text.tag_add("center", 1.0, "end")



If you run the above code, you will observe that the cursor of the text window will have justification set to its center.