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

grid

The grid—as the name suggests—treats the parent widget as a grid containing rows and columns of cells. If you are familiar with spreadsheet software, grid will work in the same way. The grid lines will not be visible, they are just conceptual.

To specify the position within the grid, the row and column keywords are used. These accept integer values and begin at 0, not 1. A widget placed with grid(row=0, column=0) will be to the left of a widget at grid(row=0, column=1). Underneath these would sit a widget placed at grid(row=1, column=0).

To make a widget span more than one cell, use columnspan for a horizontal size increase and rowspan for a vertical increase. So, to make our hypothetical bottom widget sit below both, the full argument set would be grid(row=1, column=0, columnspan=2).

By default, a widget will sit in the center of its assigned cell(s). In order to make the widget touch the very edge of its cell, we can use the sticky argument. This argument takes any number of four constants: N, S, E, and W. These are abbreviations for North, South, East, and West. Passing in W or E will align the widget to the left or right, respectively. S and N will align to the bottom and top.

These constants can be combined as desired, so NE will align top right and SW will sit the widget bottom left.

If you wish for the widget to span the entire vertical space, use NS. Similarly, use EW to stretch to the full size in the horizontal direction.

If you instead want the widget to fill the whole cell edge to edge, NSEW will let you do this.

The pack and grid are both intended to lay out the entire content of a parent widget and apply different logic to decide where each new widget added should go. For this reason, they cannot be combined inside the same parent. Once one widget is inserted using pack or grid, all other widgets must use the same geometry manager. You can, however, pack widgets into one Frame, grid widgets into another, then pack/ grid both of those Frame widgets into the same parent. 
主站蜘蛛池模板: 阿鲁科尔沁旗| 陈巴尔虎旗| 炉霍县| 宜兴市| 马边| 梁山县| 泸溪县| 城市| 渑池县| 平阴县| 定安县| 乌兰县| 昌图县| 永川市| 白玉县| 云梦县| 察隅县| 漳浦县| 洛宁县| 张掖市| 呼玛县| 民权县| 酒泉市| 黔西县| 昌邑市| 沾益县| 江安县| 濮阳市| 昌都县| 崇仁县| 托克托县| 朝阳市| 水城县| 吉林省| 石屏县| 平乐县| 福清市| 安泽县| 苍溪县| 靖江市| 那曲县|