-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
75 lines (59 loc) · 2.17 KB
/
test.py
File metadata and controls
75 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
#
# Simple PyQt/PySide Web Browser.
#
# pythonassets.com
#
#
import sys
from PyQt6.QtCore import QUrl
from PyQt6.QtWidgets import QApplication, QHBoxLayout, QLineEdit
from PyQt6.QtWidgets import QMainWindow, QPushButton, QVBoxLayout
from PyQt6.QtWidgets import QWidget
from PyQt6.QtWebEngineWidgets import QWebEngineView
class Widgets(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("Simple Web Browser")
self.widget = QWidget(self)
# Where the webpage is rendered.
self.webview = QWebEngineView()
self.webview.load(QUrl("https://www.python.org/"))
self.webview.urlChanged.connect(self.url_changed)
# Navigation buttons.
self.back_button = QPushButton("<")
self.back_button.clicked.connect(self.webview.back)
self.forward_button = QPushButton(">")
self.forward_button.clicked.connect(self.webview.forward)
self.refresh_button = QPushButton("Refresh")
self.refresh_button.clicked.connect(self.webview.reload)
# URL address bar.
self.url_text = QLineEdit()
# Button to load the current page.
self.go_button = QPushButton("Go")
self.go_button.clicked.connect(self.url_set)
self.toplayout = QHBoxLayout()
self.toplayout.addWidget(self.back_button)
self.toplayout.addWidget(self.forward_button)
self.toplayout.addWidget(self.refresh_button)
self.toplayout.addWidget(self.url_text)
self.toplayout.addWidget(self.go_button)
self.layout = QVBoxLayout()
self.layout.addLayout(self.toplayout)
self.layout.addWidget(self.webview)
self.widget.setLayout(self.layout)
self.setCentralWidget(self.widget)
def url_changed(self, url):
"""Refresh the address bar"""
self.url_text.setText(url.toString())
def url_set(self):
"""Load the new URL"""
self.webview.setUrl(QUrl(self.url_text.text()))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Widgets()
window.show()
try:
sys.exit(app.exec_())
except AttributeError:
sys.exit(app.exec())