Tkinter Label - Right align text
Tkinter Label - Right align text
You can right align the text in a Label widget in Tkinter as shown in the following screenshot.
To right align the text in a Label widget in Tkinter, set the anchor parameter to "e" (east) and the justify parameter to "right".
The syntax to specify the anchor and justify parameters in a Label widget constructor, so that the text is right aligned, is as shown in the following.
tk.Label(anchor="e", justify="right")
In this tutorial, you will learn how to right align the text in a Label widget in Tkinter, with examples.
Examples
1. Right align text in a Label widget
In this example, we shall create a Label widget with some text, and set the alignment of the text to right.
We have set the background color and width, so that we can visually check if the text is actually right aligned or not.
Program
import tkinter as tk
# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")
# Create a label widget
label = tk.Label(
window,
text="Hello World!",
anchor="e",
justify="right",
width=25,
bg="lightgreen"
)
# Pack the label widget to display it
label.pack()
# Run the application
window.mainloop()
Output
Run on Windows 10.
Run on a MacOS.
Summary
In this Python Tkinter tutorial, we learned how to right align text in a Label widget, with examples.