PyGobject(十八)布局容器之ActionBar

来源:互联网 发布:太阳能热水器 知乎 编辑:程序博客网 时间:2024/05/21 17:22

  • GtkActionBar
    • 继承关系
    • Methods
    • Virtual Methods
    • Properties
    • Signals
    • 例子

Gtk.ActionBar

继承关系

Gtk.ActionBar被设计为呈现上下文动作。
通常水平放置在主要内容的下方

Gtk.ActionBar是Gtk.Bin的直接子类
这里写图片描述

Methods

方法修饰词 方法名及参数 static new () get_center_widget () pack_end (child) pack_start (child) set_center_widget (center_widget)

Virtual Methods

Properties

Name Type Flags Short Description

Signals

Name Short Description

例子

这里写图片描述
代码:

#!/usr/bin/env python3# Created by xiaosanyu at 16/7/7# section 019TITLE = "ActionBar"DESCRIPTION = """Gtk.ActionBar is designed to present contextual actions.It is expected to be displayed below the content and expand horizontally to fill the area"""import gigi.require_version("Gtk", "3.0")from gi.repository import Gtkicons = ["edit-cut", "edit-paste", "edit-copy"]class ActionBarWindow(Gtk.Window):    def __init__(self):        Gtk.Window.__init__(self, title="ActionBar Example")        self.set_size_request(250, 200)        box = Gtk.VBox()        ab = Gtk.ActionBar()        theme = Gtk.IconTheme.get_default()        for i, icon in enumerate(icons):            if theme.has_icon(icon):                image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)                button = Gtk.Button()                button.add(image)                if i == 0:                    ab.pack_start(button)                elif i == 1:                    ab.set_center_widget(button)                elif i == 2:                    ab.pack_end(button)        box.pack_end(ab, False, False, 0)        box.pack_start(Gtk.TextView(), True, True, 0)        self.add(box)def main():    win = ActionBarWindow()    win.connect("delete-event", Gtk.main_quit)    win.show_all()    Gtk.main()if __name__ == "__main__":    main()

分析主要代码
创建Gtk.ActionBar

ab = Gtk.ActionBar()

创建三个图片按钮,第一个放在最左边,第二个放在中间,第三个放在最末尾

icons = ["edit-cut", "edit-paste", "edit-copy"]theme = Gtk.IconTheme.get_default()for i, icon in enumerate(icons):    if theme.has_icon(icon):        image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)        button = Gtk.Button()        button.add(image)        if i == 0:            ab.pack_start(button)        elif i == 1:            ab.set_center_widget(button)        elif i == 2:            ab.pack_end(button)





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

0 0
原创粉丝点击