-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyWeb.py
More file actions
63 lines (50 loc) · 1.96 KB
/
PyWeb.py
File metadata and controls
63 lines (50 loc) · 1.96 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
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction, QLineEdit, QStatusBar
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl
class Browser(QMainWindow):
def __init__(self):
super().__init__()
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://www.google.com"))
self.setCentralWidget(self.browser)
self.showMaximized()
# Barra de navegación
navbar = QToolBar()
self.addToolBar(navbar)
# Botón de retroceso
back_btn = QAction('Atrás', self)
back_btn.triggered.connect(self.browser.back)
navbar.addAction(back_btn)
# Botón de avance
forward_btn = QAction('Adelante', self)
forward_btn.triggered.connect(self.browser.forward)
navbar.addAction(forward_btn)
# Botón de recargar
reload_btn = QAction('Recargar', self)
reload_btn.triggered.connect(self.browser.reload)
navbar.addAction(reload_btn)
# Botón de inicio
home_btn = QAction('Inicio', self)
home_btn.triggered.connect(self.navigate_home)
navbar.addAction(home_btn)
# Barra de URL
self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.navigate_to_url)
navbar.addWidget(self.url_bar)
# Actualizar la barra de URL
self.browser.urlChanged.connect(self.update_url)
# Barra de estado
self.status = QStatusBar()
self.setStatusBar(self.status)
def navigate_home(self):
self.browser.setUrl(QUrl("http://www.google.com"))
def navigate_to_url(self):
url = self.url_bar.text()
self.browser.setUrl(QUrl(url))
def update_url(self, q):
self.url_bar.setText(q.toString())
app = QApplication(sys.argv)
QApplication.setApplicationName("Navegador Web")
window = Browser()
app.exec_()