Python3 Tkinter-Pack

1.创建

from tkinter import *

root=Tk()

print(root.pack_slaves())
Label(root,text='pack').pack()
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

2.改变大小

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
Label(root,text='pack').pack()
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

3.添加多个组件

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
for i in range(5):
    Label(root,text='pack'+str(i)).pack()
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

4.子组件布局

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
Label(root,text='pack1',bg='red').pack(fill=Y)
Label(root,text='pack2',bg='blue').pack(fill=BOTH)
Label(root,text='pack3',bg='green').pack(fill=X)
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

5.组件布局

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
Label(root,text='pack1',bg='red').pack(fill=Y,expand=1)
Label(root,text='pack2',bg='blue').pack(fill=BOTH,expand=1)
Label(root,text='pack3',bg='green').pack(fill=X,expand=1)
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

6.改变组件布局

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
Label(root,text='pack1',bg='red').pack(fill=Y,expand=1,side=LEFT)
Label(root,text='pack2',bg='blue').pack(fill=BOTH,expand=1,side=RIGHT)
Label(root,text='pack3',bg='green').pack(fill=X,expand=1,side=LEFT)
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

7.组件间距

from tkinter import *

root=Tk()
root.geometry('80x80+0+0')
print(root.pack_slaves())
Label(root,text='pack1',bg='red').pack(fill=Y,expand=1,side=LEFT)
Label(root,text='pack2',bg='blue').pack(fill=BOTH,expand=1,side=RIGHT,padx=10)
Label(root,text='pack3',bg='green').pack(fill=X,expand=1,side=LEFT,pady=10)
print(root.pack_slaves())

root.mainloop()

Python3 Tkinter-Pack

上一篇:比特币学习笔记(二)---在windows下调试比特币源码


下一篇:Asp.net中GridView使用详解(引)【转】