python tkinter pack 布局管理问题,fill无法向两边延伸

import tkinter as tk

root = tk.Tk()
root.geometry('1920x1080+0+0')

f_1 = tk.Frame(root, height=70, bg='red')
f_1.pack(side='top', anchor='n', expand='no', fill='both')
f_2 = tk.Frame(root, bg='blue')
f_2.pack(side='top', anchor='n', expand='yes', fill='both')
f_3 = tk.Frame(root, height=27, bg='red')
f_3.pack(side='top', anchor='n', expand='no', fill='both')

f_2_1 = tk.Frame(f_2, width=250, bg='#FF00FF')      # 洋红
f_2_1.pack(side='left', anchor='w', expand='yes', fill='y')

f_2_2 = tk.Frame(f_2, bg='#48D1CC')                 # 墨绿
f_2_2.pack(side='left', anchor='w', expand='yes', fill='both')

f_2_3 = tk.Frame(f_2, width=320, bg='#FFFF00')      # 黄色
f_2_3.pack(side='left', anchor='e', expand='yes', fill='y')

root.mainloop()

这是布局代码,得到的效果是这样的

img

我想让中间墨绿色的向x两边延伸到红色和黄色的边上,并且拉伸窗口的时候中间部分能够相应的变化,两边的不变,但是调试了好久没找到怎么回事,劳烦各位帮忙看看问题出在哪了

你需要在f_2_2 = tk.Frame(f_2, bg='#48D1CC') 这里,设置一下宽度width=1350,改写为:f_2_2 = tk.Frame(f_2, bg='#48D1CC',width=1350)即可。

f_2_2 = tk.Frame(f_2, bg='#48D1CC',width=1350)                 # 墨绿
f_2_2.pack(side='left', anchor='center', expand='yes', fill='both')

你最好使用画布Canvas组件,在上面绘制矩形,这样就可以避免这样的问题