TinUI面板布局
TinUI中有三个可用面板类,分别管理拓展、纵向、横向面板布局。
ExpandPanel
class ExpandPanel(BasePanel):
def __init__(self, canvas, child=None, padding=(0, 0, 0, 0), min_width=0, min_height=0, bg='', bd=9):
...
set_padding(padding)
设置内边距,四元组(top, right, bottom, left)。
set_min_size(min_width, min_height)
设置最小尺寸。
set_child(child)
设置托管元素。
update_layout(x1, y1, x2, y2)
设置布局区域,一般使用如下方法,将ExpandPanel作为TinUI框架的根面板:
b=BasicTinUI(a,bg='white')
b.pack(fill='both',expand=True)
rp=ExpandPanel(b)
def update(e):
rp.update_layout(5,5,e.width-5,e.height-5)
b.bind('<Configure>',update)
VerticalPanel
class VerticalPanel(ExpandablePanel):
def __init__(self, canvas, padding=(0, 0, 0, 0), spacing=0, min_width=0, min_height=0, bg='', bd=9):
...
set_padding,set_min_size,update_layout同ExpandPanel。
set_spacing(spacing)
设置元素间间距。
clear_children()
删除下辖所有元素。
add_child(child, size=None, min_size=0, weight=0, index=-1)
若size未指定,当child是控件时,获取对应方向上的尺寸;如果是横向面板,则获取最大控件高度;否则为100,注意,每次布局时都会重新获取控件元素的尺寸,将增大计算负荷。
当weight>0时,该元素的尺寸将根据剩余空间按比例分配,否则其固定尺寸。
使用index参数控制控件插入的顺序,默认在末尾插入(除了-1,插入逻辑同python列表插入)。
remove_child(index)
删除位置在index的托管元素。
如果index不是int而是元素uid或者面板,则删除指定元素或面板,不存在则会报错。
pop_child(index)
不再管理位置在index的托管元素,并返回这个元素。
如果index不是int而是元素uid或者面板,则取消指定元素或面板的托管,不存在则会报错。
HorizonPanel
同VerticalPanel,但add_child未指定size时,判断纵向面板最大控件宽度。
CardPanel
class CardPanel(ExpandablePanel):
def __init__(self, canvas, card_width=100, card_height=100, padding=(0, 0, 0, 0), h_spacing=5, v_spacing=5, min_width=0, bg='', bd=9):
...
- card_width::卡片宽度
- card_height::卡片高度
- h_spacing::水平间距
- v_spacing::垂直间距
set_card_size(width, height)
调整卡片尺寸。
set_spacing(horizontal=None, vertical=None)
设置卡片间距。
add_child(child, index=-1)
在指定位置插入托管元素。