45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
#!/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() |