Skip to content

Commit b619dc6

Browse files
committed
add pyqt5-18
1 parent 52cda5a commit b619dc6

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626

2727
* p16_显示`opencv`图像格式 [源码下载](p16_OpenCV) [博文地址](https://xugaoxiang.com/2021/04/14/pyqt5-16-opencv/)
2828

29-
* p17_画饼图 [源码下载](p17_qtpychart) [博文地址](https://xugaoxiang.com/2021/08/04/pyqt5-17-pyqtchart/)
29+
* p17_画饼图 [源码下载](p17_qtpychart) [博文地址](https://xugaoxiang.com/2021/08/04/pyqt5-17-pyqtchart/)
30+
31+
* p18_画饼图 [源码下载](p18_打开网页) [博文地址](https://xugaoxiang.com/2021/08/05/pyqt5-18-pyqtwebengine/)

p18_打开网页/main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
3+
from PyQt5.QtCore import *
4+
from PyQt5.QtGui import *
5+
from PyQt5.QtWidgets import *
6+
from PyQt5.QtWebEngineWidgets import QWebEngineView
7+
8+
9+
class MainWindow(QMainWindow):
10+
def __init__(self):
11+
super(MainWindow, self).__init__()
12+
self.setWindowTitle('网页示例')
13+
self.setGeometry(10, 20, 1080, 720)
14+
15+
self.browser = QWebEngineView()
16+
self.browser.load(QUrl('https://xugaoxiang.com'))
17+
18+
# 打开本地html文件
19+
# self.browser = QWebEngineView()
20+
# self.browser.load(QUrl('file:///test.html'))
21+
22+
# 使用setHtml方法显示
23+
# self.browser = QWebEngineView()
24+
# self.browser.setHtml('''
25+
# <!DOCTYPE html>
26+
# <html lang="en">
27+
# <head>
28+
# <meta charset="UTF-8">
29+
# <title>本地网页文件示例</title>
30+
# </head>
31+
# <body>
32+
# <p>PyQt5打开本地HTML文件示例,采用setHtml方法</p>
33+
# </body>
34+
# </html>
35+
# ''')
36+
37+
self.setCentralWidget(self.browser)
38+
39+
40+
if __name__ == '__main__':
41+
app = QApplication(sys.argv)
42+
win = MainWindow()
43+
win.show()
44+
app.exec_()

p18_打开网页/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyQtWebEngine

p18_打开网页/test.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>本地网页文件示例</title>
6+
</head>
7+
<body>
8+
<p>PyQt5打开本地HTML文件示例</p>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)