PyQt5 web page displayed in the window

To display the window in PyQt5 map, you can use QWebEngineView class (note: not the old version of the class), of course, compare versions 5.11 and above do not have this class, you can use pip install! The following are two methods of installation, we recommend the second because the first may be too slow or fail!

pip install PyQtWebEngine

pip install PyQtWebEngine -i https://pypi.douban.com/simple/

Well, after installation can be achieved load the page chatter, as follows:

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
import sys

class MainWindow(QMainWindow):
    def __init__(self):
        super(QMainWindow, self).__init__()
        self.setWindowTitle('显示网页')
        self.resize(800, 800)
        # 新建一个QWebEngineView()对象
        self.qwebengine = QWebEngineView(self)
        # 设置网页在窗口中显示的位置和大小
        self.qwebengine.setGeometry(20, 20, 600, 600)
        # 在QWebEngineView中加载网址
        self.qwebengine.load(QUrl(r"https://www.csdn.net/"))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())

Operating results as shown below, enter the URL of want to load it, or quite simply mess!
Here Insert Picture Description

Published 17 original articles · won praise 3 · Views 1804

Guess you like

Origin blog.csdn.net/weixin_43350361/article/details/104869311