我有gtk.Window,我需要抓住关闭。我需要关闭show message消息对话框并单击Yes如果窗口应该关闭,除非有一个显示窗口
谢谢。
答案 0 :(得分:4)
处理delete-event信号。返回False关闭,True返回取消。
答案 1 :(得分:3)
以下是我如何使用它:
# in constructor:
self.connect('destroy', gtk.main_quit)
self.connect('delete-event', self.on_destroy)
def on_destroy(self, widget=None, *data):
# return True --> no, don't close
messagedialog = gtk.MessageDialog(parent=self, flags= gtk.DIALOG_MODAL & gtk.DIALOG_DESTROY_WITH_PARENT,
type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK_CANCEL, message_format="Click on 'Cancel' to leave the application open.")
messagedialog.show_all()
result=messagedialog.run()
messagedialog.destroy()
if result==gtk.RESPONSE_CANCEL:
return True
return False