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

pack

The pack geometry manager acts based on the concept of using up free space within the parent widget. When packing, you can specify at which end of the free space to put the widget, and how it will grow along with said free space (as the window itself grows and shrinks). The geometry manager than assigns widgets into said free space, leaving as little empty space as possible.

The pack geometry manager is primarily controlled by three keyword arguments:

  • side: On which end of the available space do you want to place the widget? The options are defined as constants within Tkinter, as LEFT, RIGHT, TOP, and BOTTOM.
  • fill: Do you want the widget to fill any available space around it? The options are also constants: X or Y. These are Cartesian, meaning X is horizontal and Y is vertical. If you want the widget to expand in both directions, use the BOTH constant.
  • expand: Should the widget resize when the window does? This argument is a Boolean, so you can pass True or 1 to make the widget grow with the window.

These are not the only arguments that can be provided to pack; there are others which handle things such as spacing, but these are the main ones you will use. The pack geometry manager is somewhat difficult to explain, but tends to create very readable code thanks to its use of words to describe positions.

The order in which widgets are packed matters greatly. Suppose you have two buttons which you wish to stack vertically, with one underneath the other. The first button, which you call pack(side=tk.BOTTOM) on, will be at the very bottom of the main window. The next widget, which is packed with side=tk.BOTTOM, will then appear above it. Bear this in mind if your widgets appear to be out of order when using pack as your geometry manager.

主站蜘蛛池模板: 邢台市| 资溪县| 襄汾县| 泽普县| 慈溪市| 宣城市| 双柏县| 尼勒克县| 新干县| 荣昌县| 兴仁县| 永平县| 凤翔县| 若尔盖县| 潞西市| 潞西市| 张家界市| 松潘县| 盐津县| 邵阳县| 杂多县| 麟游县| 宁乡县| 石狮市| 四子王旗| 栾城县| 拉孜县| 涡阳县| 日土县| 梁山县| 铁岭市| 五指山市| 大宁县| 屯昌县| 普洱| 蕲春县| 柏乡县| 枝江市| 安国市| 龙南县| 三台县|