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

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.

主站蜘蛛池模板: 青铜峡市| 资兴市| 贡嘎县| 舒兰市| 巴彦淖尔市| 榆中县| 鲁山县| 景宁| 恩平市| 应用必备| 富阳市| 民县| 绥江县| 镇沅| 利辛县| 丹凤县| 神木县| 内丘县| 尚志市| 安远县| 桐柏县| 平南县| 云阳县| 仁化县| 荣昌县| 利津县| 方正县| 玉龙| 拉萨市| 英德市| 横峰县| 漾濞| 垫江县| 静安区| 芮城县| 永顺县| 滁州市| 游戏| 柘城县| 青海省| 巴东县|