在 TK 中创建新的顶层或按钮时,需要输入路径名。我看过一个基本代码,如下所示:
toplevel .a
...
button .a.b ...
我的问题是:点与字母的处理方式不同吗?它们是某种创建父子关系的层次分隔符吗?我查看了 wiki TK 并没有找到答案。非常感谢,-Lior
As other answers have said, dots are used to represent a hierarchy, just as / or \ is used to represent a filesystem hierarchy.
Placing widgets in a hierarchy is not, strictly speaking, necessary. One advantage in doing so is that geometry managers such as grid and pack default to managing children in their parents. For example 'pack .a.b.c' will pack the widget a.b.c within the widget .a.b. This makes it easy to do simple layouts.
The same effect in many cases can be achieved by telling grid and pack into which container a child should be placed. Foe example, 'pack .c -in .a.b' will put the widget .c in the container .a.b. This let's you keep your hierarchy shallow, and makes refactoring a little easier.
See http://www.beedub.com/book/2nd/TKINTRO.doc.html for a good introduction to tk fundamentals.
对,他们是!例如,它们将一个框架与作为小部件的内容分开:
set f [frame .hello]
button $f.b -text "Hello button"
pack $f.b
pack $f
正如您在此示例中看到的, f 被评估为变量,而不是 fb
您也可以编写 pack ${f}.b 但这不是必需的,因为点被认为不是变量的一部分。
是的 - 这是为了层次结构。查看有关该主题的TkDocs:
该框架是根的子框架,被命名为“.c”。我们可以用几乎任何东西来代替“c”,例如将其命名为“.content”。此名称纯粹供您的程序使用,因此最好选择有意义的名称。作为框架子级的控件被命名为“.c.feet”、“.c.meters”、“.c.flbl”等。如果在层次结构的更深层次有任何小部件,我们将添加另一个“。” 然后是唯一标识符。