Python in pack() Method
Python GUI pack Method
Python in pack() Method#Copyright (c)2017, Students of Software College of Northeastern University # All rightsreserved# File name :a.py# do person : Kongyun # Problem description : use pack() Method does not participate in arranging labels # Problem analysis :. The code is as follows :from tkinter import *root=Tk()lbred=Label(root,text=" Red grooved edge ",fg="red",font=(' Microsoft YaHei ',15),width=20,height=2,relief=GROOVE)lbred.pack()lbgreen=Label(root,text=" Green raised ",fg="green",font=(' Microsoft YaHei ',15),width=20,height=2,relief=RAISED)lbgreen.pack()lbblue=Label(root,text=" Blue ridge edge ",fg="blue",font=(' Microsoft YaHei ',15),width=20,height=2,relief=RIDGE)lbblue.pack()lbyellow=Label(root,text=" Yellow sunken ",fg="yellow",font=(' Microsoft YaHei ',15),width=20,height=2,relief=SUNKEN)lbyellow.pack()lbpink=Label(root,text=" Pink flat ",fg="pink",font=(' Microsoft YaHei ',15),width=20,height=2,relief=FLAT)lbpink.pack()root.mainloop()
The operation results are as follows :
notes : attribute relief Rendered for the control 3D Relief style , Yes FLAT( Flat )、RAISED( Protruding )、SUNKEN( Sunken )、GROOVE( Grooved edges ) and RIDGE( Ridge edge )5 Kind of .
Python GUI pack Methodfrom tkinter import *root = Tk()root.title("pack Method ")root.geometry("300x180")print(" Before execution ", root.pack_slaves())ok_label = Label(root, text="OK", font="Times 20 bold", fg="white", bg="blue")ok_label.pack(anchor=S, side=RIGHT, padx=10, pady=10)# root.pack_slaves()[0].forget() # Hide controls ng_label = Label(root, text="NG", font="Times 20 bold", fg="white", bg="red")ng_label.pack(anchor=S, side=RIGHT, pady=10)print(" After execution ", root.pack_slaves())for pack in root.pack_slaves(): print("info", pack.info()) print("size", pack.size())root.mainloop()
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .