DEV Community


Posted on

Say Goodbye to Chrome: Build Your Own Browser with PyQt5 and Python

Alright folks! Let's build a browser so unique and wild that even Chrome would be envious! We'll be using Python and PyQt5 to build this browser, so make sure you have both installed on your computer. If not, you can use the following command to install them:

pip install pyqt5
pip install PyQtWebEngine
Enter fullscreen mode Exit fullscreen mode

Now that we have the necessary tools, let's get into the code. The full code for this project can be found on this GitHub repository: Not only the code but also all the button images that we will be using in this project are available there.

We're using PyQt5 to create a QTabWidget and a QMainWindow, which will serve as the foundation for our browser. We're also using PyQtWebEngine to create a QWebEngineView, which will be used to display web pages.

We're creating a bunch of buttons with images like 'back.svg', 'forward.svg', 'reload.svg', 'home.svg', 'add.svg' which are available at the repository mentioned above. These buttons will have different functionality like back, forward, reload and navigate home.

We're also creating a search bar, which uses Google to search for whatever you type in. So, whether you're looking for funny cat videos or researching the latest and greatest Python libraries, our browser's got you covered!

Full Code

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        # create a QTabWidget
        self.tabs = QTabWidget()

        self.home_url = ""

        # Create a new tab and set it as the current tab
        self.add_new_tab(self.home_url, "Home")

        # create a navigation toolbar
        navbar = QToolBar()

        back_btn = QAction(QIcon('back.svg'),'', self)

        forward_btn = QAction(QIcon('forward.svg'),'', self)

        reload_btn = QAction(QIcon('reload.svg'),'', self)

        home_btn = QAction(QIcon('home.svg'),'', self)

        new_tab_btn = QAction(QIcon('add.svg'),'', self)

        # create a search bar
        self.search_bar = QLineEdit()

    def add_new_tab(self, url=None, title="blank"):
        browser = QWebEngineView()

        # set url if given
        if url:

        # create a new tab and set browser as its widget
        tab_index = self.tabs.addTab(browser, title)

        # make the new tab the current tab

        # update the url bar

    def search(self):
        url = self.search_bar.text()
        current_tab = self.tabs.currentWidget()

    def navigate_home(self):

    def update_url(self, q):

app = QApplication(sys.argv)
QApplication.setApplicationName('The Silly Surfer ')
window = MainWindow()

Enter fullscreen mode Exit fullscreen mode

Now, let's run the code and see our wild and unique browser in action! You can easily customize the browser as per your need and create something even more unique and wild.

Web Browser Using Python and PyQt5

And there you have it, folks! Your very own, one-of-a-kind browser built with PyQt5 and Python. Now you can surf the web in style, with all the fun buttons and icons to make your browsing experience extra delightful. Happy coding!

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git