默认情况下,grid中的部件不缩放。

缩放的关键:

rowconfigure()
columnconfigure()

示例代码:
 1 import tkinter as tk
 2 import tkinter.ttk as ttk
 3
 4 win=tk.Tk()
 5 win.title("CommunicationTool")
 6 win.rowconfigure(1, weight=1)
 7 win.columnconfigure(0, weight=1)
 8 #setting
 9 setFrame = tk.LabelFrame(win,text="Setting")
10 setFrame.columnconfigure(2, weight=1)
11 comLable = tk.Label(setFrame,text="COM Port: ").grid(row=0,column=0)
12 comSpiner = tk.Spinbox(setFrame,text="COM1").grid(row=0,column=1,sticky=tk.EW)
13 refrashButton = ttk.Button(setFrame,text="Refresh").grid(row=0,column=2,sticky=tk.W)
14 inputLable = tk.Label(setFrame,text="Command: ").grid(row=1,column=0)
15 inputEntry = tk.Entry(setFrame).grid(row=1,column=1,sticky=tk.EW,columnspan=2)
16 sendButton = ttk.Button(setFrame,text="Send").grid(row=1,column=3)
17 setFrame.grid(row=0,sticky=tk.EW)
18 #output
19 outputFrame = tk.LabelFrame(win,text="Output")
20 area = tk.Text(outputFrame).pack(side=tk.BOTTOM,expand=1,fill=tk.BOTH)
21 outputFrame.grid(row=1,sticky=tk.NSEW)
22
23 win.mainloop()

默认效果:

最大化效果:

02-10 03:24