pyqtwebengine=5.12
PyQt5==5.12
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.browser = QWebEngineView(self) # 如果不写self则新生成一个窗口
self.browser.setWindowTitle('技术领域占比分析')
self.browser.setWindowIcon(QIcon(LOGO_PATH))
self.browser.raise_()
self.browser.setFixedSize(QSize(1200, 850))
self.browser.move(0, 0)
self.browser.setUrl(QUrl('https://www.taobao.com')) # 网络连接
# self.browser.load(QUrl.fromLocalFile('D:/1.htmml')) # 本地h5
self.browser.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
webview套壳 防多开 多次点击激活旧窗口
文件结构如下:
依赖
loguru==0.6.0
pyinstaller
pywin32==306
PyQt5==5.12
pyqtwebengine==5.12
Pillow
config.ini
[Section1]
open_loadfile = 1
window_title = 鸿运兑奖系统
window_width = 1580
window_height = 800
prohibit_max_window = 0
window_max = 0
open_url = https://www.taobao.com
min_window_width = 1300
min_window_height = 700
settings.py
import os
BASE_DIR = os.path.dirname(__file__)
STATIC_FILE = os.path.join(BASE_DIR, 'static') # 静态资源路径
INDEX_FILE = os.path.join(STATIC_FILE, 'index.html')
CONFIG_PATH = os.path.join(BASE_DIR, 'config') # 图标文件
LOGO_PATH = os.path.join(CONFIG_PATH, "logo.png") # 图标路径
INI_PATH = os.path.join(CONFIG_PATH, "config.ini") # 配置文件
tools.py
import configparser
class MyINIFile:
def __init__(self, filename):
self.filename = filename
self.config = configparser.ConfigParser()
self.config.read(self.filename)
def read_value(self, section, key):
try:
return self.config.get(section, key)
except configparser.Error as e:
print(f"Error reading value: {
e}")
return None
def write_value(self, section, key, value):
try:
if