From 812e5863cbfad85ef4c7693822b1920661b1d55e Mon Sep 17 00:00:00 2001 From: Hector <145347438+hudomn@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:33:14 +0800 Subject: [PATCH] =?UTF-8?q?windows=E4=B8=B4=E6=97=B6web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- standalone_web_browser.py | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 standalone_web_browser.py diff --git a/standalone_web_browser.py b/standalone_web_browser.py new file mode 100644 index 00000000..443f616c --- /dev/null +++ b/standalone_web_browser.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget +from PyQt5.QtWebEngineWidgets import QWebEngineView +from PyQt5.QtCore import QUrl +import argparse + + +class StandaloneWebBrowser(QMainWindow): + def __init__(self, url="https://www.baidu.com"): + super().__init__() + self.setWindowTitle("Web浏览器") + self.setGeometry(100, 100, 640,480) + + # 创建中央部件和布局 + central_widget = QWidget() + self.setCentralWidget(central_widget) + layout = QVBoxLayout(central_widget) + + # 创建 WebEngine 视图 + self.web_view = QWebEngineView() + + # 加载网页 + self.web_view.load(QUrl(url)) + + # 添加到布局 + layout.addWidget(self.web_view) + + +def main(): + parser = argparse.ArgumentParser(description='Standalone Web Browser') + parser.add_argument('--url', type=str, default='https://www.baidu.com', + help='URL to open in the browser') + args = parser.parse_args() + + app = QApplication(sys.argv) + window = StandaloneWebBrowser(args.url) + window.show() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() \ No newline at end of file