【发布时间】:2018-11-29 07:05:33
【问题描述】:
对于一个模拟应用程序,我正在用 python 中的 Tkinter 模块设计一个 UI。我目前正在尝试为框架和窗口大小添加约束,以保持良好的界面,无论窗口大小如何。
在我的用户界面的一部分,我有这样的东西:
from tkinter import *
root = Tk()
topframe= Frame(master=root,bg='red')
midframe= Frame(master=root,bg='blue')
bottomframe= Frame(master=root,bg='yellow')
toplabel= Label(master=topframe,bg='red',text='Must be non resizable unless window cannot fit it \n (Contains buttons)',height=10)
midlabel= Label(master=midframe,bg='blue',text='Must be resizable \n (Contains a graph)',height=10)
bottomlabel= Label(master=bottomframe,bg='yellow',text='Must be non resizable unless window cannot fit it \n (Contains simulation results)',height=10)
toplabel.pack(fill=X,expand=TRUE)
midlabel.pack(fill=X,expand=TRUE)
bottomlabel.pack(fill=X,expand=TRUE)
topframe.pack(side=TOP,fill=BOTH,expand=FALSE)
midframe.pack(side=TOP,fill=BOTH,expand=TRUE)
bottomframe.pack(side=TOP,fill=BOTH,expand=FALSE)
root.mainloop()
所以我得到了这样的窗口:
但我的问题是,当我调整窗口大小以变小时,黄色部分会缩小直到消失,但我想保持大小固定,蓝色部分缩小(中间的框架)。有人有这个想法吗?
我已经尝试过 grid_propagate(False) 并且我已经看过相关的问题,但是它要么没有效果要么不适合我的示例。感谢您的帮助
【问题讨论】: