How to Use Anchor in Label Tkinter
Anchors are used to define where text is positioned relative to a reference point. When text and/or image are smaller than width, the anchor option determines where to position them. The Default Anchor is CENTER.
Anchor Attributes: NW=North West, N=North, NE=North East, W=West, CENTER, E=East, SW=South West, S=South, SE=South East.
Example:
from tkinter import *
my_window = Tk()
my_window.title("Anchor Example")
my_window.config(bg="#B4EEB4")
my_window.geometry("800x400+450+86")
my_window.state("zoomed")
lbl1 = Label(my_window, text="Johny \n Hasan", font=("Helvetica", 25, "bold"),
width=25, height=8, anchor=SE)
lbl2= Label(my_window, text="Johny \n Hasan", font=("Vrinda", 25, "bold"),
bg="#FFD700",width=25, height=8, anchor=NW)
lbl1.pack()
lbl2.pack(pady=40)
my_window.mainloop()
Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.
Post a Comment