本章节主要围绕Deepin 截图工具中都引用module 来慢慢学习吧,基本技术概念决定上层建筑嘛,希望不要被喷。
PyGTK是Deepin中用来组建GUI这一块都基本工具,说是楼房都地基一点都不为怪,截图都窗口就是这个东东建起来的。
pygtk是其中最常用到的module之一,教程如下:
http://www.pygtk.org/pygtk2tutorial/index.html
#!/usr/bin/env python
#example pygtk_test.py
import pygtk
pygtk.require('2.0')
import gtk
class Base:
def destroy(self):
'''Destroy window'''
gtk.main_quit()
def hello(self, widget, data):
'''print some data'''
print 'Hello' + data + ' this is a button click() test'
def delete_event(self, widget, event, data=None):
print "delete event occurred"
return False
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
handler1 = self.window.connect("destroy", self.destroy)
print "handler1 is :%d" % handler1
self.window.set_title("PyGTK Test Window")
self.window.set_default_size(200, 200)
self.window.set_border_width(100)
self.window.set_position(gtk.WIN_POS_CENTER)
self.button1 = gtk.Button()
self.button2 = gtk.Button()
self.button1.set_label('label1')
self.button2.set_label('label2')
handler2 = self.button1.connect("clicked", self.hello, "PyGTK")
print "handler2 is:%d" % handler2
self.button1.connect_object("clicked", gtk.Widget.destroy, self.window)
self.button1.disconnect(handler2)
self.box1 = gtk.HBox(False, 0)
self.window.add(self.box1)
self.box1.pack_start(self.button1, True, True, 0)
self.button1.show()
self.box1.pack_start(self.button2, True, True, 0)
self.button2.show()
self.box1.show()
self.window.show()
def main(self):
gtk.main()
print __name__
if __name__ == "__main__":
base = Base()
base.main()