我正在設計一個小的GUI來與我寫的一段代碼進行接口。Gtk.main()阻塞在Gtk3接口
我的問題是,Gtk.main()
命令似乎是阻止,即使我點擊銷燬按鈕時我的窗口關閉,我的終端仍然被絞死。
我也沒有看到任何信號交互。
這裏是我的示例:
#!/usr/bin/env python
from gi.repository import Gtk, Gdk, GObject
GObject.threads_init()
class Ivolution():
def __init__(self):
print "in"
self.builder = Gtk.Builder()
self.builder.add_from_file("data/ui/IvolutionWindow.glade")
#builder.connect_signals({ "on_window_destroy" : gtk.main_quit })
self.window = self.builder.get_object("ivolution_window")
print "in fin"
def on_stopbutton_clicked(self, widget):
"""
Asks the Facemovie thread to terminate
"""
print "Stop"
def on_ivolutionwindow_destroy(self, widget, data=None):
"""Called when the IvolutionWindow is closed."""
# Clean up code for saving application state should be added here.
print "Exiting"
Gtk.main_quit()
print "Exited"
if __name__ == "__main__":
app = Ivolution()
print "deb"
app.window.show()
Gdk.threads_init()
Gdk.threads_enter()
print "but"
Gtk.main()
print "end"
Gdk.thread_leave()
print "ding"
我刪除了所有非必要的部分。
Gobject和gdk.threads是我在互聯網上查看不同源代碼的測試。我不能想出他們的成功組合。
如果我運行該程序進入控制檯,這裏是我得到:
in
(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed
(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed
in fin
deb
but
即使我打的停止按鈕並關閉窗口。
一旦我關閉了我的窗口,控制檯保持不變,甚至ctrl + c也不會停止應用程序。
我確定我錯過了一些基本的東西,但作爲一個完整的GUI noob,我沒有看到什麼。 This sample code看起來真的很接近我的。任何想法?