[英]Quit PyQt4 app when loadFinished complete
I want to close the window after loadFinished complete. 我想在loadFinished完成后关闭窗口。 imagine simple code:
想象简单的代码:
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_()
Just call close() on the main window: 只需在主窗口上调用close()即可 :
def some_action(self):
# do something here
# after it's done close app
self.close()
Once the last primary window is closed, the application will automatically quit. 关闭最后一个主窗口后,应用程序将自动退出。
You could also just call the application's quit function directly: 您也可以直接调用应用程序的quit函数:
app.quit()
or, more generally: 或者,更一般而言:
QCoreApplication.instance().quit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.