我有一个带有名为openDialog的Gtk按钮的主窗口。如果我单击此按钮,则会弹出另一个Window(addName)弹出窗口。我想在我的主窗口文件中编写一个名为printHi的方法(或函数,不知道python中哪个是正确的名称)。我想运行这个printHi方法(在我的主窗口文件中),当addName窗口被销毁时。
我试过这样的事情:
def on_addName_destroy():
printHi()
但它不起作用。有什么建议吗?
答案 0 :(得分:1)
您可以使用gtk.Widget
的{{3}}信号。也可以使用gtk.Object
的{{3}}信号。这是一个连接两个信号的示例,但在您的情况下,连接到其中任何一个都应该足够了。
#!/usr/bin/env python
import gtk
def on_addName_destroy(gtkobject, data=None):
print "This is called later after delete-event callback has been called"
print "Indication that the reference of this object should be destroyed"
print "============================================"
def on_addName_delete(widget, event, data=None):
print "This is called on delete request"
print "Propagation of this event further can be controlled by return value"
print "--------------------------------------------"
return False
def show_popup(widget, data=None):
dialog = gtk.Window(gtk.WINDOW_TOPLEVEL)
dialog.set_size_request(100, 100)
label = gtk.Label("Hello!")
dialog.add(label)
dialog.connect("delete-event", on_addName_delete)
dialog.connect("destroy", on_addName_destroy)
dialog.show_all()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_size_request(100, 100)
button = gtk.Button("Popup")
button.connect("clicked", show_popup)
window.add(button)
window.connect("destroy", lambda x: gtk.main_quit())
window.show_all()
gtk.main()
希望这有帮助!