這個幾何管理器在將小部件放置在父小部件中之前將它們組織在塊中。
用法
widget.pack( pack_options )
以下是可能的選項列表 -
expand− 當設置為 true 時,小部件擴展以填充小部件父級中未使用的任何空間。
fill- 確定小部件是填充包裝器分配給它的任何額外空間,還是保持其自己的最小尺寸:NONE(默認)、X(僅水平填充)、Y(僅垂直填充)或 BOTH(水平和垂直填充) .
side- 確定父小部件的哪一側包裝:TOP(默認)、BOTTOM、LEFT 或 RIGHT。
示例
通過在不同按鈕上移動光標來嘗試以下示例 -
# !/usr/bin/python3
from tkinter import *
root = Tk()
frame = Frame(root)
frame.pack()
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )
redbutton = Button(frame, text = "Red", fg = "red")
redbutton.pack( side = LEFT)
greenbutton = Button(frame, text = "Brown", fg = "brown")
greenbutton.pack( side = LEFT )
bluebutton = Button(frame, text = "Blue", fg = "blue")
bluebutton.pack( side = LEFT )
blackbutton = Button(bottomframe, text = "Black", fg = "black")
blackbutton.pack( side = BOTTOM)
root.mainloop()
執行上述代碼時,會產生以下結果 -

相關用法
- Python 3 Tkinter place()用法及代碼示例
- Python 3 Tuple tuple()用法及代碼示例
- Python 3 Tuple len()用法及代碼示例
- Python 3 Tuple cmp()用法及代碼示例
- Python 3 Tuple max()用法及代碼示例
- Python 3 Tuple min()用法及代碼示例
- Python 3 Number tan()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 List pop()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 dictionary cmp()用法及代碼示例
- Python 3 String isupper()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 List index()用法及代碼示例
- Python 3 String decode()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 Number atan()用法及代碼示例
- Python 3 List len()用法及代碼示例
- Python 3 String maketrans()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - Tkinter pack() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。