1.安裝
pip install PyQtWebEngine
2.使用MDI
3.扁平化
self.ui.mdiArea.tileSubWindows()
4.程式碼如下
from PyQt5 import QtWidgets, QtGui, QtCore
from interface import Ui_MainWindow
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QtWidgets.QMainWindow):
def init(self):
super(MainWindow, self).init()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Menu
self.ui.pushButton.clicked.connect(self.btnclick)
def btnclick(self):
url='https://google.com'
self.ui.label.setText("aaa")
self.widget = QWidget() # +
self.s1 = QWebEngineView()
self.s2 = QWebEngineView()
self.s1.load(QUrl(url))
self.s2.load(QUrl(url))
self.sw1= self.ui.mdiArea.addSubWindow(self.s1)
self.sw1.show()
self.sw2= self.ui.mdiArea.addSubWindow(self.s2)
self.sw2.show()
self.ui.mdiArea.tileSubWindows()
if name == ‘main’:
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())