gtk PyGObject示例1

PyGObject入门

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

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
>
  >
  >
  >
    >hello world!
  >
  >
    >False>
    >Hello World>
    >800>
    >600>
    >
      >
    >
    >
      >
        >True>
        >False>
        >vertical>
        >6>
        >
          >
            >True>
            >False>
            >label>
          >
          >
            >False>
            >True>
            >0>
          >
        >
        >
          >
            >button>
            >True>
            >True>
            >True>
          >
          >
            >False>
            >True>
            >1>
          >
        >
        >
          >
            >True>
            >True>
            >False>
            >textbuffer1>
            >True>
          >
          >
            >True>
            >True>
            >2>
          >
        >
        >
          >
            >True>
            >False>
            >gtk-about>
          >
          >
            >False>
            >True>
            >3>
          >
        >
        >
          >
        >
      >
    >
  >
>

 
  
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()

运行图
gtk PyGObject示例1_第1张图片
参考链接:
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

你可能感兴趣的:(gtk,python)