0% found this document useful (0 votes)
26 views2 pages

Browser Python

The document shows code for building a basic web browser in Python using PyQt5. It imports necessary libraries, creates a main window class with a QWebEngineView widget to display web pages and a toolbar with buttons for navigation. It also includes code to update the URL bar and connect navigation buttons.

Uploaded by

wicked
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Browser Python

The document shows code for building a basic web browser in Python using PyQt5. It imports necessary libraries, creates a main window class with a QWebEngineView widget to display web pages and a toolbar with buttons for navigation. It also includes code to update the URL bar and connect navigation buttons.

Uploaded by

wicked
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import sys

from PyQt5.QtCore import *


from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *

class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.browser = QWebEngineView()
self.browser.setUrl(QUrl('http://google.com'))
self.setCentralWidget(self.browser)
self.showMaximized()

# navbar
navbar = QToolBar()
self.addToolBar(navbar)

back_btn = QAction('Back', self)


back_btn.triggered.connect(self.browser.back)
navbar.addAction(back_btn)

forward_btn = QAction('Forward', self)


forward_btn.triggered.connect(self.browser.forward)
navbar.addAction(forward_btn)

reload_btn = QAction('Reload', self)


reload_btn.triggered.connect(self.browser.reload)
navbar.addAction(reload_btn)

home_btn = QAction('Home', self)


home_btn.triggered.connect(self.navigate_home)
navbar.addAction(home_btn)

self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.navigate_to_url)
navbar.addWidget(self.url_bar)

self.browser.urlChanged.connect(self.update_url)

def navigate_home(self):
self.browser.setUrl(QUrl('http://programming-hero.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('My Cool Browser')
window = MainWindow()
app.exec_()
#https://github.com/ProgrammingHero1/my_cool_browser/blob/main/main.py

You might also like