Window management with pygtk
I'm having an issue with PyGTK and GTK Builder windows. Here's a simplified version of my code.
class GUI:
def __init__(self,parent):
builder_file = "./ui/window.builder"
self.builder = gtk.Builder()
self.builder.add_from_file(builder_file)
self.window = self.builder.get_object('main')
self.builder.connect_signals( self )
self.populate_window()
self.window.show()
def populate_window(self):
hbox = self.builder.get_object('hbox')
hbox.pack_start( somewidgets )
def on_destroy(self):
self.window.destroy()
The gtk builder file just contains a toplevel window with a horizontal packing box and signal to the destroy. This appears to work and the window is created and populated just fine, but if I try to destroy the window that has been populated with any other widgets python segfaults.
I'm thinking this it's some issue with packing new widgets that aren't in the builder file so pygtk doesn't know how to destory them开发者_StackOverflow社区, but I'm not sure though.
Thanks for any help.
Use gtk.main_quit()
.
def on_destroy(self): gtk.main_quit()
Your "destroy" handler is called when the window is yet in destruction, so this code fragment:
def on_destroy(self):
self.window.destroy()
will generate an infinite recursive call. In other terms, you are destroying something that is yet being destroyed.
This has nothing to do with GtkBuilder or hand-coded widgets, but I suspect I'm missing something because I don't know why you need to connect something to GtkWindow::destroy.
精彩评论