加载相对路径html网页
Main.py程序代码:
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle('加载本地网页')
self.setGeometry(70,70,555,330)#窗口的初始位置和大小
self.browser=QWebEngineView()
#加载本地html
#相对路径:file:///D:/spark/PyQT5_Main/Window/html/aa.html
#绝对路径:./html/aa.html
self.browser.load(QUrl(QFileInfo("./html/aa.html").absoluteFilePath()))
self.setCentralWidget(self.browser)
if __name__ == '__main__':
app=QApplication(sys.argv)
win=MainWindow()
win.show()
app.exit(app.exec_())
运行后的结果: