'''
pyqt5 简单浏览器 by 郑瑞国
'''
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('My Browser')
self.showMaximized()
self.webview = WebEngineView()
self.webview.load(QUrl("https://www.bing.com"))
self.setCentralWidget(self.webview)
class WebEngineView(QWebEngineView):
windowList = []
def createWindow(self, QWebEnginePage_WebWindowType):
new_webview = WebEngineView()
new_window = MainWindow()
new_window.setCentralWidget(new_webview)
self.windowList.append(new_window)
return new_webview
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())