I created a web browser by PyQt5 ,if I load url="http://www.google.com" have nothing issues,but if I load url = "http://192.168.0.106/get.html" ,run the code, the widgets crash.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
import sys
class MainWindow(QMainWindow):
"""docstring for MainWindow"""
def __init__(self, *arg,**kwargs):
super(MainWindow, self).__init__(*arg,**kwargs)
self.setWindowTitle("Load huobi exchange bar")
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://192.168.0.106/get.html"))
self.setCentralWidget(self.browser)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
bellow is the content of get.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>huobi exchange bar</title>
</head>
<body>
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div class="tradingview-widget-container__widget"></div>
<div class="tradingview-widget-copyright"><a href="https://cn.tradingview.com/crypto-screener/" rel="noopener" target="_blank"><span class="blue-text">sample</span></a>TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-screener.js" async>
{
"width": 1100,
"height": 512,
"defaultColumn": "overview",
"defaultScreen": "general",
"market": "crypto",
"showToolbar": true,
"colorTheme": "dark",
"locale": "zh_CN"
}
</script>
</div>
<!-- TradingView Widget END -->
</body>
</html>
my question is :how to solve the window crash when load about async js?
I do not understand why the application is broken because even if the url did not exist this should show you the error page so if you want more details of the error you should run the code in the console/CMD.
On the other hand you do not indicate that any server executes the HTML, in addition it is not necessary to use the "http://192.168.0.106" host, just load it as a local file:
├── get.html
└── main.py
import os
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
"""docstring for MainWindow"""
def __init__(self, *arg, **kwargs):
super(MainWindow, self).__init__(*arg, **kwargs)
self.setWindowTitle("Load huobi exchange bar")
self.browser = QWebEngineView()
current_dir = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(current_dir, "get.html")
url = QUrl.fromLocalFile(filename)
self.browser.setUrl(url)
self.setCentralWidget(self.browser)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())