最近断断续续地在折腾PyGTK3,发现这个也是非常有趣的说.

from gi.repository import Gtk

导入pygtk模块

PyGTK使用class来创建窗口,例如

class MyWindow(Gtk.Window):

然后渲染这个窗口.

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

其中的delete-event就是那个叉的图标,用于退出程序.

使用widget创建点击事件:

self.button1 = Gtk.Button(label="Mike Lei is so rich")
self.button1.connect("clicked", self.on_button1_clicked)

def on_button1_clicked(self, widget):
     print("Yes,it's true")

这样就会有个按钮,按钮上显示的是"Mike Lei is so rich",按下之后会显示"Yes,it’s true"

未完待续


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.