Reputation: 115
I am building an app in Python using PyQt5 and I am going to freeze it. Therefor I would like to have my python code independent from any local file path. At some point I am loading an html code with:
self.pageXXX.html_code.load(QtCore.QUrl.fromLocalFile(QtCore.QDir.current().filePath("example.html")))
How can I change this command so that I can paste the HTML code directly in the html.load()
?
Something like:
self.pageXXX.html_code.load('''
HTML code
''')
Upvotes: 0
Views: 418
Reputation: 115
As suggested by @Maurice Meyer, the problem was in the way I set QWebChannel
. I just added
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
at the top of my HTML code and then:
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtWebEngineWidgets import QWebEngineView
in my Python code. And the magic happened!
Upvotes: 1