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

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.

主站蜘蛛池模板: 边坝县| 东安县| 融水| 炎陵县| 金沙县| 杂多县| 祥云县| 汝阳县| 浮梁县| 灵武市| 五河县| 余姚市| 鹿泉市| 昌江| 冷水江市| 时尚| 维西| 郑州市| 林西县| 会理县| 宜丰县| 布尔津县| 恩平市| 大港区| 丰顺县| 信阳市| 石柱| 缙云县| 福贡县| 正宁县| 玉林市| 巴林左旗| 哈尔滨市| 马尔康县| 子洲县| 漠河县| 临泉县| 正宁县| 易门县| 镇坪县| 自治县|