-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpython_browser.py
More file actions
53 lines (39 loc) · 1.56 KB
/
python_browser.py
File metadata and controls
53 lines (39 loc) · 1.56 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
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Create a web view
self.browser = QWebEngineView()
# Set the central widget to the web view
self.setCentralWidget(self.browser)
# Create a toolbar
self.toolbar = QToolBar()
# Add a back button to the toolbar
self.back_button = QPushButton("Back")
self.toolbar.addWidget(self.back_button)
# Add a forward button to the toolbar
self.forward_button = QPushButton("Forward")
self.toolbar.addWidget(self.forward_button)
# Add a line edit to the toolbar for entering URLs
self.url_edit = QLineEdit()
self.toolbar.addWidget(self.url_edit)
# Add the toolbar to the main window
self.addToolBar(Qt.TopToolBarArea, self.toolbar)
# Connect the back and forward buttons to their respective functions
self.back_button.clicked.connect(self.browser.back)
self.forward_button.clicked.connect(self.browser.forward)
# Connect the line edit to the browser's URL changed signal
self.url_edit.textChanged.connect(self.browser.setUrl)
# Show the main window
self.show()
def navigate_to_url(self, url):
self.browser.setUrl(QUrl(url))
def update_url(self, url):
self.url_edit.setText(url)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())