Tkinter/ttk 框架和小部件定位
我在我制作的小型 gui 上对齐一些 python tkinter/ttk 小部件时遇到问题。我的 GUI 窗口有 4 个“部分”,我用框架来表示。我使用网格管理器来填充每个框架及其各自的标签、条目、组合框等。框架 2(右上角,或笛卡尔象限 1)是最大的。为了符合对称性,我将所有框架的粘性选项设置为N+S+E+W。这创建了 4 个填充整个空间的框架,其中窗口的上半部分有两个大小相等的框架,窗口的下半部分有两个大小相等的框架。我的镜框有浮雕(凸起),因此每个镜框之间都有视觉上的分离。
我的问题
我的框架 1(笛卡尔象限 2)是最小的框架,但是,使用网格,它的大小与框架 2 匹配。这个不错,我想要这个然而,frame1 的小部件也比框架 2 少得多,并且它不是将所有小部件对齐 sticky = NW (就像我的所有其他框架一样),而是首先将所有小部件居中。这导致小部件在框架中具有巨大的填充边框,使其看起来非常不均匀。我希望这些小部件位于我的frame1 的NW 边界中,并且在它们下面的框架中只有开放空间。
是否有网格方法,或者我错过了一个概念?我已经挖掘了大量的示例/论坛/等来寻找这个问题的类似描述。我希望我足够清楚,我的代码现在还没有处于非常漂亮的状态,因为我现在只是想生成我的视觉想法。如果需要更多信息或代码,我可以发布。
提前致谢, Chris。
I'm having troubles aligning some python tkinter/ttk widgets on a small gui I'm making. My gui window has 4 "sections" which I'm representing with frames. I'm using the grid manager to populate each frame with it's respective labels, entries, comboboxes, etc. Frame2 (top right, or Cartesian quadrant 1) is the biggest. To conform to symmetry, I set the sticky option of all my frames as N+S+E+W. This created 4 frames that filled the entire space, where the top half of the window has two frames of equal size, and the bottom half of the window has two frames of equal size. My frames have a relief (RAISED) so there is a visual separation of each one.
MY PROBLEM
My frame1 (Cartesian quadrant 2) is the smallest frame, but, with grid, it matches frame2 in size. This is good, I wanted this. However, frame1 also has way fewer widgets than frame 2, and instead of aligning all widgets at sticky = NW (like all my other frames), it centers all of the widgets first. This results in the widgets having a huge padded boarder in the frame, making it look very uneven. I want the widgets to be in the NW boarder of my frame1, and just have open space in the frame below them.
Is there a grid method, or a concept I've missed? I've dug through tonnes of examples/forums/etc looking for a similar description of this issue. I hope I was clear enough, my code isn't in a very presentable state right now as I am just trying to generate my visual idea right now. If more info or code is needed I can post.
Thanks in advance,
Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你的框架中有六行。使用 grid_configure 将第七行的权重设置为 1。假设所有其他行的权重为零,则该额外行将扩展以填充可用空间。
It looks like you have six rows in your frame. Use grid_configure to set tne weight of the seventh row to be 1. Assuming all the other rows have a weight of zero, this extra row will expand to fill tne available space.