0

我想在 loadFinished 完成后关闭窗口。想象一下简单的代码:

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_()
4

1 回答 1

1

只需在主窗口上调用close() :

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

关闭最后一个主窗口后,应用程序将自动退出。

您也可以直接调用应用程序的退出函数:

    app.quit()

或者,更一般地说:

    QCoreApplication.instance().quit()
于 2012-12-06T20:51:35.890 回答