从命令行或对象构造函数调用时,PyQt QWebkitWidgets不显示网页

时间:2018-09-10 17:05:43

标签: python-3.x pyqt qwebkit

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
import sys
import os

class Navigation(QWidget):
    def __init__(self):
        super().__init__()
        self.web = QWebView()
        self.web.settings().setAttribute(QWebSettings.
             JavascriptEnabled,True)
        #self.web.settings().setAttribute(QWebSettings.
        #    JavascriptCanOpenWindows, True)
        self.web.settings().setAttribute(QWebSettings.
            JSAC, True)

        #self.web.settings().setAttribute(QWebSettings.
        #DeveloperExtrasEnabled, True)
        filepath = os.path.join(
            os.path.dirname(__file__), 'MapSite.html')
        self.web.show()
        self.web.load(QUrl.fromLocalFile(filepath))

app = QApplication(sys.argv)
ex= Navigation()
app.exec_()

仅当从IDLE运行python3时,此PyQt程序才会显示网页。当我运行该程序的fom命令行或通过导入其他文件来创建Navigation类对象时,网页未显示,只是白屏

EDIT

pi@raspberrypi:~/RaspiCallSystem4 $ python3 navigation.py 
libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus system tray: no

当我从命令行执行时,给出上面的输出,Web窗口启动,但仅白页,从IDLE运行顺利执行

enter image description here

0 个答案:

没有答案