使用 pygtk 进行窗口管理
我在使用 PyGTK 和 GTK Builder 窗口时遇到问题。这是我的代码的简化版本。
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()
gtk 构建器文件仅包含一个带有水平包装框的顶层窗口和销毁信号。这似乎有效,并且窗口已创建并填充得很好,但如果我尝试销毁已填充有任何其他小部件的窗口,则会出现 python 段错误。
我认为这是打包不在构建器文件中的新小部件的问题,因此 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, but I'm not sure though.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 gtk.main_quit()。
Use
gtk.main_quit()
.当窗口尚未销毁时,将调用“销毁”处理程序,因此此代码片段:
将生成无限递归调用。换句话说,你正在摧毁一些尚未被摧毁的东西。
这与 GtkBuilder 或手工编码的小部件无关,但我怀疑我遗漏了一些东西,因为我不知道为什么需要将某些东西连接到 GtkWindow::destroy。
Your "destroy" handler is called when the window is yet in destruction, so this code fragment:
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.