'''
Tkinter教程之Place篇
'''
'''
1.使用绝对坐标将组件放到指定的位置
'''
#
-*- coding: cp936 -*-
#
不设置root的大小,使用默认
from
Tkinter
import
*
root
=
Tk()
lb
=
Label(root,text
=
'
hello Place
'
)
#
lb.place(relx = 1,rely = 0.5,anchor = CENTER)
#
使用绝对坐标将Label放置到(0,0)位置上
lb.place(x
=
0,y
=
0,anchor
=
NW)
root.mainloop()
#
x,y指定组件放置的绝对位置
'''
2.使用相对坐标放置组件位置
'''
#
-*- coding: cp936 -*-
#
不设置root的大小,使用默认
from
Tkinter
import
*
root
=
Tk()
lb
=
Label(root,text
=
'
hello Place
'
)
#
lb.place(relx = 1,rely = 0.5,anchor = CENTER)
#
使用相对坐标(0.5,0.5)将Label放置到(0.5*sx,0.5.sy)位置上
lb.place(relx
=
0.5
,rely
=
0.5
,anchor
=
CENTER)
root.mainloop()
#
relx,rely指定组件放置的绝对位置,范围为(0-1.0)
'''
3.使用place同时指定多个组件
'''
#
-*- coding: cp936 -*-
#
不设置root的大小,使用默认
from
Tkinter
import
*
root
=
Tk()
root.geometry(
'
800x600
'
)
lb
=
Label(root,text
=
'
hello Place
'
)
本文详细介绍了Tkinter库中Place布局管理器的使用方法,包括使用绝对和相对坐标定位组件,使用in属性指定放置的容器,以及事件与Place的结合应用。
最低0.47元/天 解锁文章
475

被折叠的 条评论
为什么被折叠?



