使用pack实现组件由上往下排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack()
lab2.pack()
lab3.pack()
window.mainloop()
使用pack实现组件由左往右排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(side=LEFT)
lab2.pack(side=LEFT)
lab3.pack(side=LEFT)
window.mainloop()
使用pack实现组件由下往上排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(side=BOTTOM)
lab2.pack(side=BOTTOM)
lab3.pack(side=BOTTOM)
window.mainloop()
使用pack实现组件由右往左排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(side=RIGHT)
lab2.pack(side=RIGHT)
lab3.pack(side=RIGHT)
window.mainloop()
使用pack实现组件“众”字形排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack()
lab2.pack(side=LEFT)
lab3.pack(side=RIGHT)
window.mainloop()
使用pack实现组件之间给标签间距排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(fill=X)
lab2.pack(pady=10)
lab3.pack(fill=X)
window.mainloop()
使用pack实现组件之间给标签间距左右排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(padx=30)
lab2.pack(padx=30)
lab3.pack(padx=30)
window.mainloop()
使用pack实现组件之间给横向标签间距排列
from tkinter import *
window=Tk()
window.title("这是标题")
lab1=Label(window,text="昨天打豆豆",
bg="lightyellow",
width=30)
lab2=Label(window,text="今天打豆豆",
bg="lightgreen",
width=30)
lab3=Label(window,text="明天打豆豆",
bg="lightblue",
width=30)
lab1.pack(side=LEFT)
lab2.pack(side=LEFT,padx=30)
lab3.pack(side=LEFT)
window.mainloop()