控件多了,要算每个控件行、列、rowspan,columnspan很麻烦
Frame控件上面还可以摆放控件,可以当作底板使用
可以在Frame控件上面设置网格进行Grid布局,摆放多个控件
# coding=utf-8
import tkinter as tk
root = tk.Tk()
root.geometry('800x600')
root.title('Frame布局demo')
frm00Green = tk.Frame(root,bg="green",highlightthickness=2) #背景绿色,边框宽度2
frm00Green.grid(row=0,column=0,columnspan=3,sticky="WEN")
tk.Label(frm00Green, text="Frame00 0行0列").grid(row=0,column=0,padx=6,pady=6)
frm00Green.columnconfigure(0, weight=1)
tk.Label(frm00Green, text="Frame00 0行1列").grid(row=0,column=1,padx=6,pady=6)
frm00Green.columnconfigure(1, weight=1)
frm10Red = tk.Frame(root,bg="red",highlightthickness=2) #背景红色,边框宽度2
frm10Red.grid(row=1,column=0,sticky="WESN")
tk.Label(frm10Red, text="Frame10 0行0列").grid(row=0,column=0,padx=6,pady=6)
tk.Label(frm10Red, text="Frame10 2行0列").grid(row=1,column=0,padx=6,pady=6)
frm10Red.columnconfigure(0, weight=1)
frm11Green = tk.Frame(root,bg="blue",highlightthickness=2) #背景蓝色,边框宽度2
frm11Green.grid(row=1,column=1,sticky="WESN")
tk.Label(frm11Green, text="Frame11 0行0列").grid(row=0,column=0,padx=6,pady=6)
tk.Label(frm11Green, text="Frame11 1行0列").grid(row=1,column=0,padx=6,pady=6)
tk.Label(frm11Green, text="Frame11 2行0列").grid(row=2,column=0,padx=6,pady=6)
frm11Green.columnconfigure(0, weight=1)
frm12Grey = tk.Frame(root,bg="grey",highlightthickness=2) #背景灰色,边框宽度2
frm12Grey.grid(row=1,column=2,sticky="WESN")
tk.Label(frm12Grey, text="Frame12 0行0列").grid(row=0,column=0,padx=6,pady=6)
tk.Label(frm12Grey, text="Frame12 1行0列").grid(row=1,column=0,padx=6,pady=6)
frm12Grey.columnconfigure(0, weight=1)
frm20Green = tk.Frame(root,bg="green",highlightthickness=2,height=20) #背景绿色,边框宽度2
frm20Green.grid(row=2,column=0,columnspan=3,sticky="WES")
tk.Label(frm20Green, text="Frame20 0行0列").grid(row=0,column=0,padx=6,pady=6)
frm20Green.columnconfigure(0, weight=1)
# root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
# root.rowconfigure(2, weight=1)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1)
root.mainloop()