0

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
                                ''')
Carlo Bianchi
  • 115
  • 4
  • 15

1 Answers1

1

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!

Carlo Bianchi
  • 115
  • 4
  • 15