【发布时间】:2020-05-28 14:51:58
【问题描述】:
所以我目前正在编写一段代码,稍后将集成到其他东西中以充当设置配置器。目前,我想要一个如下所示的窗口:
每个彩色框都是一个框架。此窗口不可调整大小,始终为 480x720 像素。因此,我希望我使用的 3 帧,侧边栏(黄色)、容器(蓝色)和静态(红色)始终保持相同的大小,并以大致相同的比例填充如上图所示的窗口(不需要准确)。
这个窗口的代码如下
self.window = tk.Tk()
self.windowHeight = 480
self.windowLength = 720
self.windowDimensions = str(self.windowLength)+"x"+str(self.windowHeight) #make diemnsions string; dimensions are set as a single string
self.window.geometry(self.windowDimensions)
self.window.resizable(width=False, height=False)
self.container = tk.Frame(self.window, relief="sunken", borderwidth=2) #instantiate new window
self.sideBar = tk.Frame(self.window, relief="sunken", borderwidth=2)
self.static = tk.Frame(self.window, relief="sunken", borderwidth=2)
self.sideBar.grid_propagate(False)
self.sideBar.grid(row=0, column=0)
self.container.grid(row=0,column=1)
self.static.grid(row=5, column=1)
self.configuratorObject = configuratorObject
audioButton = tk.Button(self.sideBar, text="Audio Page", command=lambda: self.raisePage("audioPage"))
colourButton = tk.Button(self.sideBar, text="Colours", command=lambda: self.raisePage("coloursPage"))
saveButton = tk.Button(self.static, text = "Save", state="disabled")
applyButton = tk.Button(self.static, text = "Apply", state="disabled")
audioButton.pack()
colourButton.pack()
saveButton.pack()
applyButton.pack()
我尝试更改网格的height 和width 参数,但它们似乎真的没有做任何事情。那么我该如何明确定义框架的布局和大小呢?
感谢任何帮助
【问题讨论】:
-
为什么要明确设置尺寸,而不是让 tkinter 完成计算最佳拟合的所有工作?另外,为什么要阻止用户调整窗口大小?
-
@BryanOakley 如果有办法让 tkinter 做到这一点,那就太好了,但是我似乎只能让 pack() 或 grid() 使框架与其内容一样大而不是填满整个窗口。我正在阻止调整大小以方便使用
-
防止调整大小与易用性相反。如果用户的分辨率与您的不同,或者他们的字体大小不同,或者他们的视力比您的差,他们可能无法使用该窗口。
-
@BryanOakley 我明白了,我只是在寻找解决我的问题的方法,谢谢
标签: python python-3.x tkinter