Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit f494ab1

Browse files
authored
Create navegador.py
1 parent 21145b7 commit f494ab1

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

navegador.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import sys
2+
from PyQt5.QtCore import *
3+
from PyQt5.QtWidgets import *
4+
from PyQt5.QtWebEngineWidgets import *
5+
6+
class MiniNavegador(QMainWindow):
7+
def __init__(self):
8+
super().__init__()
9+
10+
# Inicializa o navegador
11+
self.browser = QWebEngineView()
12+
13+
# Definindo a página inicial
14+
self.browser.setUrl(QUrl("http://www.google.com"))
15+
16+
# Barra de navegação
17+
self.url_bar = QLineEdit(self)
18+
self.url_bar.returnPressed.connect(self.navigate_to_url)
19+
20+
# Botões de navegação
21+
self.back_button = QPushButton("Voltar", self)
22+
self.forward_button = QPushButton("Avançar", self)
23+
self.refresh_button = QPushButton("Atualizar", self)
24+
25+
# Conectar os botões às funções
26+
self.back_button.clicked.connect(self.go_back)
27+
self.forward_button.clicked.connect(self.go_forward)
28+
self.refresh_button.clicked.connect(self.refresh_page)
29+
30+
# Layout dos botões
31+
button_layout = QHBoxLayout()
32+
button_layout.addWidget(self.back_button)
33+
button_layout.addWidget(self.forward_button)
34+
button_layout.addWidget(self.refresh_button)
35+
36+
# Layout principal
37+
layout = QVBoxLayout()
38+
layout.addLayout(button_layout)
39+
layout.addWidget(self.url_bar)
40+
layout.addWidget(self.browser)
41+
42+
# Configuração do widget central
43+
container = QWidget()
44+
container.setLayout(layout)
45+
self.setCentralWidget(container)
46+
47+
# Ajusta o tamanho da janela
48+
self.setWindowTitle("Mini Navegador")
49+
self.resize(1024, 768)
50+
51+
# Conectar barra de URL à mudança de página
52+
self.browser.urlChanged.connect(self.update_url)
53+
54+
def navigate_to_url(self):
55+
url = self.url_bar.text()
56+
self.browser.setUrl(QUrl(url))
57+
58+
def update_url(self, q):
59+
self.url_bar.setText(q.toString())
60+
61+
def go_back(self):
62+
"""Voltar para a página anterior."""
63+
if self.browser.canGoBack():
64+
self.browser.back()
65+
66+
def go_forward(self):
67+
"""Avançar para a próxima página."""
68+
if self.browser.canGoForward():
69+
self.browser.forward()
70+
71+
def refresh_page(self):
72+
"""Atualizar a página atual."""
73+
self.browser.reload()
74+
75+
# Função principal para rodar o aplicativo
76+
if __name__ == "__main__":
77+
app = QApplication(sys.argv)
78+
navegador = MiniNavegador()
79+
navegador.show()
80+
sys.exit(app.exec_())

0 commit comments

Comments
 (0)