PyQt5基礎學習-QWebEngineView().load(QUrl.fromLocalFile(加載本地的html文件))


加載本地的html文件

LocalHtml.py 

"""
加載本地的html頁面
"""
import os

from PyQt5.QtWidgets import *
from PyQt5.QtCore import QTimer, QDateTime
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
import sys

class WebEngineView(QMainWindow):

    def __init__(self):
        super(WebEngineView, self).__init__()
        self.setWindowTitle("裝載本地web頁面")
        self.setGeometry(5, 30, 1355, 730)

        url = os.getcwd() + os.path.sep + "HTML/test.html"
        self.browser = QWebEngineView()
        self.browser.load(QUrl.fromLocalFile(url))
        self.setCentralWidget(self.browser)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = WebEngineView()
    main.show()

    sys.exit(app.exec_())

test.html 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>測試頁面</title>
</head>
<body>
<h1>Hello PyQt5</h1>
<h2>Hello PyQt5</h2>
<h3>Hello PyQt5</h3>
<h4>Hello PyQt5</h4>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM