logo

PyQt5 browser

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:
PyQt Desktop Apps with Python

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

4 thoughts on “PyQt5 browser


  1. Thiago Farias
    - August 4, 2017

    This code no longer works
    Erro message:

    from PyQt5.QtWebKit import *
    ModuleNotFoundError: No module named 'PyQt5.QtWebKit'

    1. Frank
      - August 4, 2017

      Hi Thiago, the code works fine.
      You need to compile QtWebKit with PyQt5.

      1. Nikhil Sharma
        - January 30, 2018

        How to compile QtWebKit with PyQt5?

        1. Frank
          - February 8, 2018

          Which OS? If I remember right you have to set a flag in the makefile.

Leave a Reply

Login disabled