---
# System prepended metadata

title: pack( )方法
tags: [活用tkinter – 學習運用GUI]

---

# pack( )方法
###### tags: `活用tkinter – 學習運用GUI`



* 雖然稱之為pack( )方法，旦它其實只是在tkinker裡的一個類別

## side參數
```python=
label_1 = Label(root, text = "男人的嘴", bg = "lightgreen")
label_2 = Label(root, text = "騙人的鬼", bg = "lightyellow")

label_1.pack(side = BOTTOM)
label_2.pack(side = TOP)
```
* 結果
![](https://i.imgur.com/V5VouaH.png)


## padx / pady 參數
```python=
label_1 = Label(root, text = "男人的嘴", bg = "lightgreen")
label_2 = Label(root, text = "騙人的鬼", bg = "lightyellow")
label_3 = Label(root, text = "漂亮的女人都愛騙人", bg = "lightyellow")

label_1.pack(padx = 50)
label_2.pack(pady = 100)
label_3.pack(fill = X)
```
* 結果
![](https://i.imgur.com/KHq4gaK.png)



## ipadx / ipady 參數
```python=
label_1.pack(ipadx = 50)
label_2.pack(ipady = 100)
label_3.pack(fill = X)
```

* 結果
![](https://i.imgur.com/shwKweV.png)


## anchor 參數 (位置)
```python=
label_2.pack(anchor = SE)
```
* 結果
![](https://i.imgur.com/aDW4IvY.png)

## fill 參數
```python=
label_1(fill = X)
```


## expand 參數
```python=
label_2.pack(fill = BOTH, expand = True)
```
* 結果
![](https://i.imgur.com/xWr9RSe.png)

## pack方法
```python=
print(root.pack_slaves())
```
* 結果
![](https://i.imgur.com/XcFM4WQ.png)







{%hackmd S1DMFioCO %}