If you have a sub-window in GTK and you want to close it programmatically (e.g., pressing a save button or the escape key), is there a preferred way to close the window?
E.g.,
window.destroy()
# versus
window.emit('delete-event')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use
window.destroy()when deleting a window in PyGTK (or for that matter any kind of widget). When you callwindow.destroy()the window will emit adelete-eventevent automatically.Furthermore, when emitting a signal for an event using PyGTK, it is almost always required to also pass an event object to the emit method (see the pyGObject documentation for the emit method). When an attempt is made to pass a
gtk.gdk.Event(gtk.EVENT_DELETE)to an object’s emit method for adelete-eventit will not work. E.g:Perhaps the best way, though, is to simply use the
delstatement which will automatically delete the window/widget and do any necessary cleanup for you. Doing this is more ‘pythonic’ than callingwindow.destroy()which will leave around a reference to a destroyed window.