小编Ste*_*tef的帖子

将本地html文件加载到Python中的QWebView中

这是我的问题:我想QWebView在Python中加载一个本地html文件.编辑:我使用PySide作为Qt包.

我的代码:

class myWindow(QWidget):
    def __init__(self, parent=None):
        self.view = QWebView(self)
        filepath = "file://" + os.path.join(os.path.dirname(__file__), 'googlemap.html')
        self.view.load(QUrl(filepath))
Run Code Online (Sandbox Code Playgroud)

这只是向我展示了一个空白的小部件.如果我改变

self.view.load(QUrl(filepath)
Run Code Online (Sandbox Code Playgroud)

通过

self.view.load(QUrl("http://www.google.com/"))
Run Code Online (Sandbox Code Playgroud)

它工作正常.

但是,该文件显然位于良好的目录中,我可以直接使用浏览器打开相同的文件.

编辑2:我的Raspberry Pi 2更新后出现问题(运行上面的代码)

python qt qwebview

3
推荐指数
1
解决办法
4980
查看次数

标签 统计

python ×1

qt ×1

qwebview ×1