Tkinter Entry - Center align text
Tkinter Entry - Center align text
In Tkinter, you can center align the text entered in the Entry widget, using justify parameter, as shown in the following screenshot.
To center align the text in an Entry widget in Tkinter, you can set the justify parameter to "center" when creating Entry using tk.Entry().
For example, the following code creates an Entry widget with center aligned text.
tk.Entry(window, justify="center")
In this tutorial, you will learn how to center align the text in an Entry widget, with examples.
Examples
1. Center align text in Entry widget
In this example, we create a basic Tk window with an Entry widget. We center align the text in this Entry widget.
Python Program
import tkinter as tk
# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")
label = tk.Label(window, text="Enter your input")
label.pack()
# Create an Entry widget with text aligned center
entry = tk.Entry(window, justify="center")
entry.pack()
# Run the application
window.mainloop()
Output
In Windows
In MacOS
Summary
In this Python Tkinter tutorial, we have seen how to center align the text in an Entry widget in Tkinter, with examples.