← Go Back

How to Justify Text on Textbox in Tk (tkinter)

When creating an instance of the ttk.Entry class, use the justify parameter:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.geometry("400x300")
# Possible alignments:
# - tk.LEFT (default value)
# - tk.RIGHT
# - tk.CENTER
entry = ttk.Entry(justify=tk.CENTER)
entry.pack()
root.mainloop()

See also our tutorial on textboxes: Textbox (Entry) in Tk (tkinter).

tkinter desktop-applications


🐍 You might also find interesting: