立即學習:https://edu.csdn.net/course/play/19711/343109?utm_source=blogtoedu
pack布局:
1)最常用的布局,順序排列布局方法
2)完成了簡單的組件位置碼放,但如果內部布局處理機制跟不上的話,也可能會達不到理想的布局
?
組件.pack(fill = "",side = "",anchor = "",expand = )
?
fill默認不填充,side默認為上下排列,anchor默認為中間,expand默認為0即否
?
pack四個參數
?
代碼演示:(side參數和anchor參數)
import tkinter#導入創建窗體的相關模塊
import osimage_path = r'C:\Users\jinlin\Desktop\python_further_study\GUI編程\resources' + os.sep + 'linlianqin.gif'#因為每個平臺的分隔符不一樣,所以用os.sep可以自動切換到相應平臺的分隔符class Mainwindow():#創建窗口類def __init__(self):root = tkinter.Tk()#創建主體窗口root.title('linlianqin')#定義窗體的名字root.geometry('500x500')#定義窗體的初始大小root.maxsize(1200,1200)#設置窗口可以顯示的最大尺寸#----------------------對組件進行pack布局-------------------------# --------------side參數-------------------image = tkinter.PhotoImage(file = image_path)image_label = tkinter.Label(root,image = image)image_label.pack(side = "left")#將其放在左邊text = tkinter.Text(root)text.insert("current","pack布局演示")text.pack(side = "right")#---------------anchor------------image = tkinter.PhotoImage(file=image_path)image_label = tkinter.Label(root, image=image)image_label.pack(anchor="ne") # 將其放在左邊text = tkinter.Text(root)text.insert("current", "pack布局演示")text.pack(anchor="center")root.mainloop()#顯示窗口,這個代碼一定要放在所有窗口設置的后面if __name__ == '__main__':Mainwindow()#將窗體類實例化
?