![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I center the text in a Tkinter Text widget?
Tkinter text widget is a multiline text input widget. It is used to insert, delete, and add textual data in the input field. It provides many built-in functions and attributes in its widget class.
To configure and align the text at the CENTER of a Tkinter Text widget, we can use justify=CENTER property.
Example
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") text=Text(win) # Configure the alignment of the text text.tag_configure("tag_name", justify='center') # Insert a Demo Text text.insert("1.0", "How do I center align the text " "in a Tkinter Text widget?") # Add the tag in the given text text.tag_add("tag_name", "1.0", "end") text.pack() win.mainloop()
Output
Run the above code to display a window with a sample text placed at the center of the Text widget.
Advertisements