- Tkinter GUI Programming by Example
- David Love
- 321字
- 2021-08-27 18:49:07
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.
- Android應(yīng)用程序開發(fā)與典型案例
- Kubernetes實戰(zhàn)
- DevOps入門與實踐
- 碼上行動:零基礎(chǔ)學(xué)會Python編程(ChatGPT版)
- HTML5+CSS3網(wǎng)站設(shè)計教程
- Reactive Programming With Java 9
- Hands-On Enterprise Automation with Python.
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- 算法訓(xùn)練營:提高篇(全彩版)
- Clojure for Machine Learning
- Apache Camel Developer's Cookbook
- Advanced Python Programming
- Python物理建模初學(xué)者指南(第2版)
- 城市信息模型平臺頂層設(shè)計與實踐
- Learning Puppet