Tkinter pack anchor parameter
The anchor parameter sets the position of the widget control in the window, in this article anchor is the position of the content of the accusation in the control area (in the actual example it is the position of the label text in the label area).
Tkinter pack anchor Example#1
Create a label with the content OK at the bottom right of the window, where the spacing between the label and the right and bottom of the window is 10 pixels.
from tkinter import *
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
oklabel=Label(root,text="OK",
font="Times 20 bold",
fg="white",bg="blue")
oklabel.pack(anchor=S,side=RIGHT,padx=10,pady=10)
root.mainloop()
Output:
Tkinter pack anchor Example#2
Add the design of a NO content label in white letters on a red background.
from tkinter import *
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
oklabel=Label(root,text="OK",
font="Times 20 bold",
fg="white",bg="blue")
oklabel.pack(anchor=S,side=RIGHT,padx=10,pady=10)
nolabel=Label(root,text="NO",
font="Times 20 bold",
fg="white",bg="red")
nolabel.pack(anchor=S,side=RIGHT,pady=10)
root.mainloop()
Output: