官术网_书友最值得收藏!

How it works…

The first label is placed with the relwidth and relheight options set to 0.25, which means that its width and height are 25% of its parent container. By default, widgets are placed at the x=0 and y=0 positions and aligned to north-west, that is, the top-left corner of the screen.

The second label is placed at the absolute position—x=100and aligned to the top border with the anchor option set to the tk.N (north) constant. Here, we also specified an absolute size with width and height.

The third label is centered on the window using the relative positioning and setting the anchor to tk.CENTER. Remember that a value of 0.5 for relx and relwidth means half of the parent's width and a value of 0.5 for rely, and relheight means half of the parent's height.

The fourth label is placed on top of label_c by passing it as the in_ argument (note that Tkinter suffixes it with an underscore because in is a reserved keyword). When using in_, you might notice that the alignment is not geometrically exact. In our example, we had to add an offset of 2 pixels in each direction to perfectly overlap the right-bottom corner of label_c.

Finally, the fifth label uses absolute positioning and relative size. As you may have already noticed, these dimensions can be easily switched since we assume a parent container of 200 x 200 pixels; however, only relative weights will work as expected if the main window is resized. You can test this behavior by resizing the window.

主站蜘蛛池模板: 德兴市| 运城市| 临安市| 荣成市| 綦江县| 南和县| 凤阳县| 宁阳县| 利辛县| 宜丰县| 徐闻县| 大新县| 巴东县| 岳阳市| 桦南县| 乌拉特前旗| 遂川县| 翼城县| 九寨沟县| 北票市| 岐山县| 辉县市| 元氏县| 南川市| 满城县| 保靖县| 广灵县| 枣阳市| 河东区| 浦县| 延寿县| 绵竹市| 灵石县| 荆州市| 莆田市| 丹江口市| 盐亭县| 罗平县| 青海省| 香河县| 闸北区|