Creating your own browser using Python

Hey there! In this tutorial, we will be learning to create a simple browser in Python using PyQt5 in PyCharm.

Qt is a set of cross-platform C++ libraries that implement high-level APIs for accessing various aspects of modern desktop and mobile systems such as location and positioning services, Bluetooth connectivity, etc.
PyQt5 is a comprehensive set of Python bindings for Qt v5, that enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.


  1. Firstly, open PyCharm and create a project titled Browser. Then open the terminal and type the below-listed commands to install the respective libraries.
    pip install PyQt5
    pip install PyQtWebEngine
  2. Then, within the file in thiproject, type the below-specified code. Refer to the code’s comments regarding various functionalities supported by the browser and their implementations.
    # Import necessary libraries
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    from PyQt5.QtWebEngineWidgets import *
    import sys
    # Create a main window class
    class MainWindow(QMainWindow):
        # Constructor of this class
        def __init__(self):
            super(MainWindow, self).__init__()
            # To provide a widget for viewing and editing web documents:
            self.browser = QWebEngineView()
            # To set default browser homepage as google homepage:
            # To set browser as central widget of main window:
            # To open browser in a maximized window:
            # To create a navigation bar:
            navbar = QToolBar()
            # To add the navigation bar to the browser:
            # To add back button within navigation bar:
            back_btn = QAction('⮜', self)
            # To add forward button within navigation bar:
            forward_btn = QAction('⮞', self)
            # To add reload button within navigation bar:
            reload_btn = QAction('⟳', self)
            # To add URL bar within navigation bar:
            self.url_bar = QLineEdit()
        # To navigate to desired URL specified within URL bar:
        def open_url(self):
            url = self.url_bar.text()
        # To update the URL bar contents when navigated from one page to another:
        def update_url(self, q):
    # To call constructor of the C++ class QApplication:
    # Here, sys.argv is used to initialize the QT application
    app = QApplication(sys.argv)
    # To specify name of the browser:
    # To create an object of MainWindow class defined above:
    window = MainWindow()
    # To run the main event loop and wait until exit() is called:

To access the arrowhead and reload symbols used in the above code, click here.


In the video below, you can see the output of our project that we have just built:

You can see our browser is ready.

Also read, Implement Browser Automation using Selenium with Python


Leave a Reply

Your email address will not be published. Required fields are marked *