简体   繁体   English

如何使用包创建左、右和中心框架?

[英]How to create left, right, and center frames with pack?

I have a left and right frame right now and tried creating a center frame but the problem is the left frame takes up more space and pushes the center frame to the right so any widgets I put in it aren't actually centered.我现在有一个左右框架,并尝试创建一个中心框架,但问题是左框架占用更多空间并将中心框架向右推,因此我放入的任何小部件实际上都没有居中。 Is there any way to make it work?有没有办法让它工作?

    self.leftside = ttk.Frame(self)
    self.leftside.pack(expand=True, fill=BOTH, side=LEFT, anchor=W)

    self.center = ttk.Frame(self)
    self.center.pack(expand=True, fill=BOTH, side=LEFT, anchor=CENTER)

    self.rightside = ttk.Frame(self)
    self.rightside.pack(expand=True, fill=BOTH, side=RIGHT, anchor=E)

If you are wanting to guarantee that the center section says centered, grid is going to be a better choice than pack since you can configure grid to force the other two columns to be the same size, and to have the center region grow or shrink to fill the rest of the space.如果你想保证中心部分是居中的, grid将是比pack更好的选择,因为你可以配置grid以强制其他两列具有相同的大小,并使中心区域增长或缩小到填充其余的空间。

It would look something like this:它看起来像这样:

    self.leftside.grid(row=0, column=0, sticky="nsew")
    self.rightside.grid(row=0, column=2, sticky="nsew")
    self.center.grid(row=0, column=1, sticky="nsew")

    self.grid_rowconfigure(0, weight=1)
    self.grid_columnconfigure((0,2), uniform="equal")
    self.grid_columnconfigure(1, weight=1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM