我正在尝试打开一个对话框,并在收到回复后再次关闭它。据我了解, .destroy() 或 .hide() 应该从屏幕上删除窗口。但是窗口冻结并保持打开状态。我究竟做错了什么?
这是我的代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gtk
import time
class MyWindow(gtk.Dialog):
def __init__(self, parent=None, filename="Filename.jpg"):
gtk.Dialog.__init__(self, "Window", parent, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
self.set_default_size(150, 100)
box = self.get_content_area()
self.usr_label = gtk.Label("User-Name:\t")
self.usr_entry = gtk.Entry()
box.add(self.usr_label)
box.add(self.usr_entry)
self.show_all()
dialog = MyWindow(filename="foobar")
response = dialog.run()
if response != gtk.RESPONSE_OK:
exit()
dialog.hide()
dialog.destroy()
time.sleep(15)
print("foo")