In openPage
you bind the web view object to a local variable web
. The web view is automatically destroyed when the variable goes out of scope (when the function returns). You need to keep a reference to the view, perhaps by return
like this:
def openPage():
web = QWebView()
web.load(QUrl('http://www.google.com'))
web.setFixedSize(500, 500)
web.show()
return web
if __name__ == '__main__':
app = QApplication(sys.argv)
web = openPage()
sys.exit(app.exec_())