Tkinter pack Method
pack is actually a category in Python tkinter, which provides the following methods for us to use.
Method | Description |
---|---|
slaves() |
Pass back all widget control objects |
info() |
Pass back the corresponding value for the pack option |
forget() |
Hide the widget control, you can use pack(options,…) Restore the display |
location(x,y) |
Return whether this point is in the cell, if yes return the coordinates, if not return (-1,-1) |
size() |
Transfer back the widget control size |
propagate(boolean) |
True means the parent window size is determined by the child control, the default is True |
Tkinter pack Example
Lists the contents of the widget control before and after execution.
from tkinter import *
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
print("Before Execution",root.pack_slaves())
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)
print("After Execution",root.pack_slaves())
root.mainloop()
Output:
The following is the result of the execution in the Python Shell window.