1、pack管理器
(1)
from tkinter import *
root=Tk()
listbox=Listbox(root)
listbox.pack(fill=BOTH,expand=True)
for i in range(10):
listbox.insert(END,str(i))
mainloop()
(2)横向填充
from tkinter import *
root=Tk()
Label(root,text=“red”,bg=“red”,fg=“white”).pack(fill=X)
Label(root,text=“green”,bg=“green”,fg=“black”).pack(fill=X)
Label(root,text=“blue”,bg=“blue”,fg=“white”).pack(fill=X)
mainloop()
(3)纵向填充
from tkinter import *
root=Tk()
Label(root,text=“red”,bg=“red”,fg=“white”).pack(side=LEFT)
Label(root,text=“green”,bg=“green”,fg=“black”).pack(side=LEFT)
Label(root,text=“blue”,bg=“blue”,fg=“white”).pack(side=LEFT)
mainloop()
2、grid用法
(1)
from tkinter import *