什么是正确的:widget.rowconfigure 或 widget.grid_rowconfigure? [英] What is correct: widget.rowconfigure or widget.grid_rowconfigure?

查看:18
本文介绍了什么是正确的:widget.rowconfigure 或 widget.grid_rowconfigure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用网格几何管理器时.假设您有:

When using grid geometry manager. Let's say you have:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
ttk.Button(root, text="Hello World").grid(sticky=tk.NSEW)
root.mainloop()

指定行/列权重的部分也可以编码为:

The part where you specify the weight of the row/column can also be coded up as:

root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)

对于这个例子,什么是正确的方法:widget.rowconfigure 或 widget.grid_rowconfigure?为什么?

奖励:从实施 POV 来看,为什么两者都有效?

Bonus: From an implementation POV, why do both work?

推荐答案

widget.rowconfigure 实际上只是 widget.grid_rowconfigure 的别名.在 tkinter 的源代码中有这行代码:

widget.rowconfigure is literally just an alias for widget.grid_rowconfigure. In the source code for tkinter is this line of code:

rowconfigure = grid_rowconfigure

我不知道事实,但我怀疑 widget.rowconfigure 只是为了方便而添加的.坦率地说,直到我读到这个问题,我才知道它的存在.

I don't know for a fact, but I suspect that widget.rowconfigure was just added for convenience. Frankly, I didn't even know it existed until I read this question.

在我看来,grid_rowconfigure 是合适的名称.我这么说是因为 tkinter 是底层 tcl/tk 解释器的接口,而在 tcl/tk 中,命令是 grid rowconfigure.由于大多数 tkinter 函数尽可能接近地反映 tcl/tk 函数的命名约定,grid_rowconfigure 是自然的选择.

In my opinion, grid_rowconfigure is the proper name to use. I say that because tkinter is an interface to an underlying tcl/tk interpreter, and in tcl/tk the command is grid rowconfigure. Since most tkinter functions mirror the naming conventions of the tcl/tk functions as close as possible, grid_rowconfigure is the natural choice.

这篇关于什么是正确的:widget.rowconfigure 或 widget.grid_rowconfigure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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