Gtk.Alignment
继承关系
Gtk.Alignment控制子部件的对齐方式和大小。
Gtk.Alignment是Gtk.Bin的直接子类
Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (xalign, yalign, xscale, yscale) |
get_padding () | |
set (xalign, yalign, xscale, yscale) | |
set_padding (padding_top, padding_bottom, padding_left, padding_right) |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
bottom-padding | int | d/r/w | The padding to insert at the bottom of the widget. deprecated |
left-padding | int | d/r/w | The padding to insert at the left of the widget. deprecated |
right-padding | int | d/r/w | The padding to insert at the right of the widget. deprecated |
top-padding | int | d/r/w | The padding to insert at the top of the widget. deprecated |
xalign | float | d/r/w | 水平对齐方式,0.0左对齐,1.0右对齐 deprecated |
xscale | float | d/r/w | 水平剩余空间分配给子部件,0.0不分配,1.0分配全部剩余空间 deprecated |
yalign | float | d/r/w | 垂直对齐方式,0.0上对齐,1.0下对齐 deprecated |
yscale | float | d/r/w | 垂直剩余空间分配给子部件,0.0不分配,1.0分配全部剩余空间 deprecated |
Signals
Name | Short Description |
---|
例子
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/7
# section 020
TITLE = "Alignment"
DESCRIPTION = """
The Gtk.Alignment widget controls the alignment and size of its child widget.
It has four settings: xscale, yscale, xalign, and yalign.
"""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
anchor = {"Left": (0, 0, 0, 0), "Right": (1, 0, 0, 0), "Top": (0.5, 0, 0, 0), "Buttom": (0.5, 1, 0, 0),
"Center": (0.5, 0.5, 0, 0), "XFull": (0.5, 0.5, 1, 0), "YFull": (0.5, 0.5, 0, 1)}
class AlignmentWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Alignment Example")
self.set_size_request(500, 200)
grid = Gtk.Grid()
grid.set_border_width(20)
grid.set_column_spacing(20)
grid.set_row_spacing(20)
for i, (key, value) in enumerate(anchor.items()):
frame = Gtk.Frame.new()
frame.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
frame.set_size_request(150, 100)
align = Gtk.Alignment.new(value[0], value[1], value[2], value[3])
button = Gtk.Button(key)
align.add(button)
frame.add(align)
grid.attach(frame, i % 3, i / 3, 1, 1)
self.add(grid)
def main():
win = AlignmentWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
分析主要代码
定义七个Alignment参数
anchor = {"Left": (0, 0, 0, 0), "Right": (1, 0, 0, 0), "Top": (0.5, 0, 0, 0), "Buttom": (0.5, 1, 0, 0),
"Center": (0.5, 0.5, 0, 0), "XFull": (0.5, 0.5, 1, 0), "YFull": (0.5, 0.5, 0, 1)}
根据上述7组信息创建7个Alignment,每个Alignment中添加一个button,将这7个Alignment添加到7个frame中
for i, (key, value) in enumerate(anchor.items()):
frame = Gtk.Frame.new()
frame.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
frame.set_size_request(150, 100)
align = Gtk.Alignment.new(value[0], value[1], value[2], value[3])
button = Gtk.Button(key)
align.add(button)
frame.add(align)
grid.attach(frame, i % 3, i / 3, 1, 1)
代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728