PyGobject(二十二)布局容器之Frame

  • GtkFrame
    • 继承关系
    • Methods
    • Virtual Methods
    • Properties
    • Signals
    • 例子
  • 附录
    • GtkShadowType

Gtk.Frame

Gtk.Frame 四周显示边框,并且有一个文本,通常显示在左上角,可以通过Gtk.Frame.set_label_align()方法设置文本位置

继承关系

Gtk.Frame是Gtk.Bin的直接子类
PyGobject(二十二)布局容器之Frame_第1张图片
这里写图片描述

Methods

方法修饰词 方法名及参数
static new (label)
get_label ()
get_label_align ()
get_label_widget ()
get_shadow_type ()
set_label (label)
set_label_align (xalign, yalign)
set_label_widget (label_widget)
set_shadow_type (type)

Virtual Methods

do_compute_child_allocation (allocation)

Properties

Name Type Flags Short Description
label str r/w/en Frame显示的文本
label-widget Gtk.Widget r/w 可以用一个Gtk.Widget来代替label
label-xalign float r/w/en 水平位置,0.0靠左,1.0靠右,默认为0.0
label-yalign float r/w/en 垂直位置,0.0在横线之下,1.0在横线之上,默认为0.5
shadow-type Gtk.ShadowType r/w/en 外轮廓样式。没有效果

Signals

Name Short Description

例子

PyGobject(二十二)布局容器之Frame_第2张图片
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/7
# section 024
TITLE = "Frame"
DESCRIPTION = """
The frame widget is a bin that surrounds its child with a decorative frame and an optional label.
If present, the label is drawn in a gap in the top side of the frame.
The position of the label can be controlled with Gtk.Frame.set_label_align()
"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class FrameWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Frame Example")
        self.set_size_request(250, 200)
        self.set_border_width(10)
        frame = Gtk.Frame.new("Frame")
        frame.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
        frame.add(Gtk.Entry())

        self.add(frame)


def main():
    win = FrameWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()

PyGobject(二十二)布局容器之Frame_第3张图片
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/7
# section 025
TITLE = "Frame_created_by_ui"
DESCRIPTION = ""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

UIINFO = """

<interface>
    
    <object class="GtkWindow" id="window1">
        <property name="can_focus">Falseproperty>
        <signal name="delete-event" handler="onDeleteWindow" swapped="no"/>
        <child>
            <object class="GtkFrame">
              <child type="label">
                <object class="GtkLabel" id="frame-label">
                    <property name="label">frameproperty>
                object>
              child>
              <child>
                <object class="GtkEntry" id="frame-content" />
              child>
            object>
        child>
    object>
interface>

"""


class Handler:
    @staticmethod
    def onDeleteWindow(*args):
        Gtk.main_quit(*args)


def main():
    builder = Gtk.Builder()
    builder.add_from_string(UIINFO)
    builder.connect_signals(Handler())

    window = builder.get_object("window1")
    window.show_all()

    Gtk.main()


if __name__ == "__main__":
    main()

两个例子比较简单,这里不做详述

附录

Gtk.ShadowType

class Gtk.ShadowType
Bases: GObject.GEnum

改变Gtk.Frame外轮廓的不同样式.

请注意,许多主题不区分各种阴影类型的外观:要么是他们没有明显的阴影(Gtk.Shadow Type.NONE),或者任何其他值。

NONE = 0

没有轮廓.

IN = 1

向内凹陷

OUT = 2

想外凸出,就像一个Button.

ETCHED_IN = 3

凹陷的3D外观.

ETCHED_OUT = 4

凸出的3D外观.





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

你可能感兴趣的:(PyGObject,PyGobject详解)