python logo

pyqt5 browser


Python hosting: Host, run, and code Python in the cloud!
QWebView Class Simplified QWebView class simplified

PyQt5 supports a widget that displays websites named QWebView.

QWebView uses the Webkit rendering engine
The web browser engine is used by Safari, App Store and many OS X applications.

The load() method opens the url (QUrl) in the argument. You can create a QUrl using: QUrl(url).

The show() method is required to display the widget.

Related course:

Installation


To use this widget you may need to install an additional package:


sudo apt-get install python3-pyqt5.qtwebkit

Read more about PyQt5.

PyQt5 webkit example


The example below loads a webpage in a PyQt5 window.


#!/usr/bin/env python

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow

app = QApplication(sys.argv)

web = QWebView()
web.load(QUrl("https://pythonspot.com"))
web.show()

sys.exit(app.exec_())

pyqt5-webkit Webkit in PyQt5

Download PyQT5 Examples

BackNext





Leave a Reply:




Adem Sun, 4 Apr 2021

Hi bro, its error : No module named 'PyQt5.QtWebKit'. What can i do? -sudo apt-get install python3-pyqt5.qtwebkit- its not working.

Frank Sun, 4 Apr 2021

This is an installation problem. Sometimes PyQt5.QtWebkit is not included with the installation (not compiled). Try these command

sudo apt-get install python3-pyqt5.qtwebengine
sudo apt install python3-pyqt5.qtmultimedia
You can also try upgrading PyQt
pip uninstall PyQt5
pip install PyQt5==5.11.3