Python PyQt5 GUI Script to Build Internet Web Browser Using PyQtWebEngine Library Full Project For Beginners

Python PyQt5 GUI Script to Build Internet Web Browser Using PyQtWebEngine Library Full Project For Beginners


Welcome folks today in this blog post we will be building a very basic web browser in python using the PyQt5 library. All the full source code of the application will be given below




Get Started



In order to get started we need to install the following libraries using the pip command as shown below


pip install pyqt5


pip install pyqtwebengine


After installing all these libraries make an file and copy paste the following code



# importing required libraries 
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
import os 
import sys 

# creating main window class 
class MainWindow(QMainWindow): 

    # constructor 
    def __init__(self, *args, **kwargs): 
        super(MainWindow, self).__init__(*args, **kwargs) 

        # creating a QWebEngineView 
        self.browser = QWebEngineView() 

        # setting default browser url as google 

        # adding action when url get changed 

        # adding action when loading is finished 

        # set this browser as central widget or main window 

        # creating a status bar object 
        self.status = QStatusBar() 

        # adding status bar to the main window 

        # creating QToolBar for navigation 
        navtb = QToolBar("Navigation") 

        # adding this tool bar tot he main window 

        # adding actions to the tool bar 
        # creating a action for back 
        back_btn = QAction("Back", self) 

        # setting status tip 
        back_btn.setStatusTip("Back to previous page") 

        # adding action to the back button 
        # making browser go back 

        # adding this action to tool bar 

        # similarly for forward action 
        next_btn = QAction("Forward", self) 
        next_btn.setStatusTip("Forward to next page") 

        # adding action to the next button 
        # making browser go forward 

        # similarly for reload action 
        reload_btn = QAction("Reload", self) 
        reload_btn.setStatusTip("Reload page") 

        # adding action to the reload button 
        # making browser to reload 

        # similarly for home action 
        home_btn = QAction("Home", self) 
        home_btn.setStatusTip("Go home") 

        # adding a separator in the tool bar 

        # creating a line edit for the url 
        self.urlbar = QLineEdit() 

        # adding action when return key is pressed 

        # adding this to the tool bar 

        # adding stop action to the tool bar 
        stop_btn = QAction("Stop", self) 
        stop_btn.setStatusTip("Stop loading current page") 

        # adding action to the stop button 
        # making browser to stop 

        # showing all the components 

    # method for updating the title of the window 
    def update_title(self): 
        title = 
        self.setWindowTitle("% s - Geek Browser" % title) 

    # method called by the home action 
    def navigate_home(self): 

        # open the google 

    # method called by the line edit when return key is pressed 
    def navigate_to_url(self): 

        # getting url and converting it to QUrl objetc 
        q = QUrl(self.urlbar.text()) 

        # if url is scheme is blank 
        if q.scheme() == "": 
            # set url scheme to html 

        # set the url to the browser 

    # method for updating url 
    # this method is called by the QWebEngineView object 
    def update_urlbar(self, q): 

        # setting text to the url bar 

        # setting cursor position of the url bar 

# creating a pyQt5 application 
app = QApplication(sys.argv) 

# setting name to the application 
app.setApplicationName("Geek Browser") 

# creating a main window object 
window = MainWindow() 

# loop 


See also  Python 3 Tkinter FFMPEG Script to Transcode and Compress Videos to GIF or AVI GUI Desktop App Full Project For Beginners


Now when you execute the python script by typing the below command






Leave a Reply