windows临时web
This commit is contained in:
parent
4f6c6bee7d
commit
812e5863cb
45
standalone_web_browser.py
Normal file
45
standalone_web_browser.py
Normal file
@ -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()
|
||||
Loading…
Reference in New Issue
Block a user