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!
Handling delete event in pygtk/glade
-
06-03-2022 - |
Question
I have a GUI designed in glade, using python/gtk in the background.I want to handle the delete event
and display a "Are you sure?"-message dialog.I have been trying to handle the delete and destroy events, but failing to do so.any light?
#!/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()
This code opens a simple window .On clicking on close button, it prints hello and exits.(I want the window to remain open)
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow