在 Tkinter 中用网格填充屏幕 X? [英] Filling screen X with grid in Tkinter?

查看:62
本文介绍了在 Tkinter 中用网格填充屏幕 X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你们中的任何 Tkinter 专家是否可以帮助我解决一个问题,你们中的任何人都知道是否有替代方法来为网格打包 fill=X 或 fill=Y 命令?或者一些会添加到这个函数中的代码?(我找了一圈也没找到)

I was wondering if any of you Tkinter experts out there could help me with a question, do any of you know if there is a alternative to packs fill=X or fill=Y commands for grids? Or some code that would add in this function? (I have searched around for a bit and couldn't find anything)

推荐答案

使用 sticky 属性使对象填充它们所在的行和/或列.

Use the sticky attribute to make objects fill the row and/or column that they are in.

使用 grid_rowconfiguregrid_columnconfigure一>.权重"定义了一旦所有孩子都被安排好,网格将如何分配任何额外的空间.默认情况下,行和列的权重为零,这意味着它们不使用任何额外空间.

Apply a weight to the rows and/or columns to get them to use any extra space in the container using grid_rowconfigure and grid_columnconfigure. The "weight" defines how grid will allocate any extra space once all the children are arranged. By default, rows and columns have zero weight, meaning they don't use any extra space.

例如:

frame = tk.Frame(...)
l1 = tk.Label(frame, ...)
l2 = tk.Label(frame, ...)
l1.grid(row=0, column=0, sticky="nsew")
l2.grid(row=1, column=1, stickky="nsew")
frame.grid_rowconfigure(0, weight=1)
frame.grid_columnconfigure(0, weight=1)

这篇关于在 Tkinter 中用网格填充屏幕 X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆