2012-12-06 36 views
0

我想在loadFinished完成後關閉窗口。 想象的簡單代碼:當loadFinished完成時退出PyQt4應用程序

class Example(QWebView): 
    def __init__(self): 
     QWebView.__init__(self) 
     self.frame = self.page().mainFrame() 
     self.frame.loadFinished.connect(self.some_action) 

    def some_action(self): 
     # do something here 
     # after it's done close app 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    url = QUrl("some_website") 
    br = Example() 
    br.load(url) 
    br.show() 
    app.exec_() 

回答

1

就叫close()在主窗口中:

def some_action(self): 
    # do something here 
    # after it's done close app 
    self.close() 

一旦最後一個主窗口關閉,應用程序將自動退出。

你也可以只調用應用程序的功能quit直接:

app.quit() 

,或者更一般地說:

QCoreApplication.instance().quit() 
+0

非常感謝您! – Vor

相關問題