Python 在pygtk/glade中处理删除事件

Python 在pygtk/glade中处理删除事件,python,user-interface,gtk,pygtk,glade,Python,User Interface,Gtk,Pygtk,Glade,我在glade中设计了一个GUI,在后台使用python/gtk。我想处理delete事件,并显示一个“确定吗?”-消息对话框。我一直在尝试处理delete和destroy事件,但没有成功。有什么线索吗 #!/usr/bin/python import .... stuff class App: def __init__(self): self.gladefile = 'test.glade' windowname = 'window'# This must ma

我在glade中设计了一个GUI,在后台使用python/gtk。我想处理
delete事件
,并显示一个“确定吗?”-消息对话框。我一直在尝试处理delete和destroy事件,但没有成功。有什么线索吗

#!/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并退出。(我希望窗口保持打开状态)

您必须返回
True
,以停止错误上的回调
中删除事件的传播,如中所述。在您当前的代码中,回调函数没有返回函数所需的任何布尔值,我猜返回的是
False
(请检查\u window\u delete\u事件上
的签名,返回类型为布尔值)

希望这有帮助

你试过什么?你是怎么失败的?除非你详细说明,否则没有人能帮助你。