gtk PyGObject示例1

PyGObject入门

使用Gtk.Builder引入glade的UI文件

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkAccelGroup" id="accelgroup1"/>
  <object class="GtkTextBuffer" id="textbuffer1">
    <property name="text" translatable="yes">hello world!</property>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">Hello World</property>
    <property name="default_width">800</property>
    <property name="default_height">600</property>
    <child>
      <placeholder/>
    </child>
    <child>
      <object class="GtkBox">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">6</property>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">label</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="button1">
            <property name="label" translatable="yes">button</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkTextView" id="textview1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="cursor_visible">False</property>
            <property name="buffer">textbuffer1</property>
            <property name="monospace">True</property>
          </object>
          <packing>
            <property name="expand">True</property>
            <property name="fill">True</property>
            <property name="position">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkImage" id="image1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="stock">gtk-about</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">3</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
def btn1_callback(inst):
    print("hello")
    
builder = Gtk.Builder()
builder.add_from_file('hello.glade')
window = builder.get_object('window1')
button1 = builder.get_object('button1')
window.show()
window.connect("destroy",Gtk.main_quit)
button1.connect("pressed",btn1_callback)
Gtk.main()

运行图
在这里插入图片描述
参考链接:
https://pygobject.readthedocs.io/en/latest/guide/api/signals.html

https://developer.gnome.org/platform-overview/unstable/tour-summary.html.zh_CN

https://blog.csdn.net/a87b01c14/article/details/52085512

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值