Create Your Own Browser in Python using PyQt5

 Create Your Own Browser Like Chrome in Python using PyQt5

Create Your Own Browser in Python using PyQt5

Source Code 


import sys
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtCore 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_butn = QAction('Back', self)
        back_butn.triggered.connect(self.browser.back)
        navbar.addAction(back_butn)        

        forward_butn = QAction('Forward',self)
        forward_butn.triggered.connect(self.browser.forward)
        navbar.addAction(forward_butn)        

        reload_butn = QAction("Reload" , self)
        reload_butn.triggered.connect(self.browser.reload)
        navbar.addAction(reload_butn)        

        home_butn = QAction("Home" , self)
        home_butn.triggered.connect(self.navigate_home)
        navbar.addAction(home_butn)
       
        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://google.com"))

    def navigate_to_url(self):

        url = self.url_bar.text()
        self.browser.setUrl(QUrl(url))    

    def update_url(self, b):

        self.url_bar.setText(b.toString())        
        
app = QApplication(sys.argv)

QApplication.setApplicationName("Browser - Bhavik Agarwal")
window = MainWindow()

app.exec_()

If you like the content kindly share it and appreciate in comments. Also, suggestions for improvement are welcomed always.

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment (0)

Previous Post Next Post