亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
[有趣的Python 6] PyGtk中窗口的事件處理
[打印本頁]
作者:
sakulagi
時(shí)間:
2005-06-08 08:31
標(biāo)題:
[有趣的Python 6] PyGtk中窗口的事件處理
還記得我們上次的PyGtk的程序么。我們顯示了一個(gè)光禿禿的窗口。而且不能關(guān)閉!呵呵。這樣太不象話了。我們來看一個(gè)復(fù)雜一點(diǎn)的例子,順便看一下PyGtk的事件處理機(jī)制:
import gtk
class Shell:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy_event, None)
self.window.connect("delete_event", self.delete_event, None)
self.initContainer()
self.window.add(self.container)
self.container.show()
self.window.show()
def initContainer(self):
self.helloButton = gtk.Button("Hello World")
self.helloButton.connect("clicked", self.hello, None)
self.quitButton = gtk.Button("Quit")
self.quitButton.connect_object("clicked", gtk.Widget.destroy, self.window)
self.container = gtk.HBox()
self.container.add(self.helloButton)
self.container.add(self.quitButton)
self.helloButton.show()
self.quitButton.show()
return self.container
def delete_event(self, widget, event, data = None):
print "delete event caught"
return False
def destroy_event(self, widget, event, data = None):
print "destroy event caught"
gtk.main_quit()
def hello(self, widget, event, data=None):
print "Hello PyGtk World!"
def main(self):
gtk.main()
print __name__
if __name__ == "__main__":
shell = Shell()
shell.main()
復(fù)制代碼
如果有Gtk編程經(jīng)驗(yàn)的話,可以很容易讀懂這段代碼。其實(shí)Gtk的機(jī)制很簡單,就是在某個(gè)widget上,為某一個(gè)特定的事件注冊(cè)一個(gè)callback函數(shù)。當(dāng)事件發(fā)生時(shí),對(duì)應(yīng)的callback事件會(huì)被調(diào)用。
對(duì)于delete_event,這個(gè)事件通常是由window manager來發(fā)出,點(diǎn)擊窗口右上教的"X"就會(huì)觸發(fā)這個(gè)事件。
對(duì)于connect_object(event, callback, widget)這個(gè)函數(shù),其效果是這樣的:
callback(widget)
復(fù)制代碼
會(huì)被調(diào)用。
在本例子里,gtk.Widget.destroy(self.window)會(huì)被調(diào)用。而gtk.Widget.destroy(widget)的作用是向widget發(fā)出destroy信號(hào)。如果widget注冊(cè)了這個(gè)signal的callback,本例中是Shell.destroy_event()函數(shù)。結(jié)果是程序的退出。
作者:
dragonII
時(shí)間:
2005-07-06 11:41
標(biāo)題:
[有趣的Python 6] PyGtk中窗口的事件處理
如何在一個(gè)notebook的頁面內(nèi)精確定位
notebook分為標(biāo)簽和頁面兩項(xiàng),如何將他們標(biāo)識(shí)出來,這樣才能完成對(duì)他們的操作
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2