PyQtWebEngine
2022/9/19原创小于 1 分钟约 145 字
安装环境
pip install PyQtWebEngine
实例
# -*- coding: UTF-8 -*-
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
# 修改安装 pip3 install PyQtWebEngine
import threading
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle('范例')
self.setGeometry(100, 100, 1024, 768)
self.browser = QWebEngineView()
# self.browser.load(QUrl('https://www.baidu.com'))
self.browser.setHtml('''<html><head><meta http-equiv="refresh" content><body>123</body></head></html>''')
self.setCentralWidget(self.browser)
t=threading.Thread(target=self.demo)
t.start()
def demo(self):
try:
time.sleep(3)
print('刷新')
self.browser.page().action(QWebEnginePage.Reload).trigger()
except Exception as e:
print(e)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MainWindow()
win.show()
app.exit(app.exec_())