2

我有一个在glade中设计的 GUI,在后台使用 python/gtk。我想处理delete event并显示“你确定吗?”-消息对话框。我一直在尝试处理删除和销毁事件,但没有做所以。任何光?

#!/usr/bin/python
import .... stuff




class App:
  def __init__(self):


    self.gladefile = 'test.glade'
    windowname = 'window'# This must match the window name in glade
    self.wTree = gtk.glade.XML(self.gladefile, windowname)# object for acessing widgets


    dic={
    # Also need to set project2's signal tab
       'on_window_delete_event':self.on_erro,
       'on_window_destroy_event':self.on_erro,
         }

    self.wTree.signal_autoconnect (dic)
    self.op=self.wTree.get_widget('window')
    self.op.show()

  def on_erro(self,widget,*args):

        print 'hello'






app = App()
gtk.main()

此代码打开一个简单的窗口。单击关闭按钮时,它会打印 hello 并退出。(我希望窗口保持打开状态)

4

1 回答 1

5

You have to return True in order to stop propagation of the delete event in the callback on_erro as mentioned in the documentation for "delete-event". In your current code, the callback is not returning any boolean value as required by the function, which I am guessing is returning False (Please check the signature for on_window_delete_event callback functions, the return type is boolean)
Hope this helps!

于 2013-02-03T20:31:46.007 回答