Python with PYQT5 labirary Web browser Sample Code for learning

Python with PYQT5 labirary Web browser Sample Code for learning

You learn and make beautiful web browser using PYQT5 labirary in python language and make some more functionality in this example. I think  you can visit more posts and you can see a proxy settings post in this blog.
and I sending a unique browser for you in my next post with user agent settings and proxy settings also in one file. I make beautiful buttons with png images for a beautiful web browser. I hope you will make a web browser using these codes with minimum time and improve functionality with your desired functions. So keep learning with best approach.






Editor: Muhammad AmanUllah

A simple PYQT5 labiraries used and make beautiful web browser with complete coding.

Here is an example of a simple web browser app created using PyQt5:


This code creates a new instance of the QMainWindow class, which serves as the main window for the app. It then creates a QWebEngineView object, which is used to display web pages, and sets its URL to "https://www.google.com".

It also creates an address bar, back, forward and reload button with the functionality. The layout of the widgets is managed using QVBoxLayout and QHBoxLayout. And it sets the central widget and show the window.

This is just a sample code, you can customize it according to your requirement. You can add many other functionality and design it in a more beautiful way.

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

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        # Create the QWebEngineView
        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl("https://www.google.com"))
        
        # Create the address bar
        self.address_bar = QLineEdit()
        self.address_bar.returnPressed.connect(self.load_url)
        
        # Create the back, forward, and reload buttons
        self.back_button = QPushButton("<")
        self.back_button.clicked.connect(self.browser.back)
        self.forward_button = QPushButton(">")
        self.forward_button.clicked.connect(self.browser.forward)
        self.reload_button = QPushButton("Reload")
        self.reload_button.clicked.connect(self.browser.reload)
        
        # Add the widgets to the layout
        self.layout = QVBoxLayout()
        self.nav_bar = QHBoxLayout()
        self.nav_bar.addWidget(self.back_button)
        self.nav_bar.addWidget(self.forward_button)
        self.nav_bar.addWidget(self.address_bar)
        self.nav_bar.addWidget(self.reload_button)
        self.layout.addLayout(self.nav_bar)
        self.layout.addWidget(self.browser)
        
        # Set the central widget and show the window
        self.central_widget = QWidget()
        self.central_widget.setLayout(self.layout)
        self.setCentralWidget(self.central_widget)
        self.show()
        
    def load_url(self):
        url = self.address_bar.text()
        if not url.startswith("http://") and not url.startswith("https://"):
            url = "http://" + url
        self.browser.setUrl(QUrl(url))
        
app = QApplication(sys.argv)
window = MainWindow()
app.exec_()

Post a Comment

0 Comments