Score:0

from PyQt5.QWebEngineWidgets import * Does not work

ge flag

I tried Installing and uninstalling PyQtWebEngine with pip3 install PyQtWebEngine (Did not work) What am i doing wrong code

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
import os
import sys

class MainWindow(QMainWindow):

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


        self.browser = QWebEngineView()

        self.browser.setUrl(QUrl("http://google.com"))

        self.browser.urlChanged.connect(self.update_urlbar)

        self.browser.loadFinished.connect(self.update_title)

        self.setCentralWidget(self.browser)

        self.status = QStatusBar()

        self.setStatusBar(self.status)

        navtb = QToolBar("Navigation")

        self.addToolBar(navtb)

        back_btn = QAction("Back", self)

        back_btn.setStatusTip("Back to previous page")

        back_btn.triggered.connect(self.browser.back)

        navtb.addAction(back_btn)

        next_btn = QAction("Forward", self)
        next_btn.setStatusTip("Forward to next page")

        next_btn.triggered.connect(self.browser.forward)
        navtb.addAction(next_btn)

        reload_btn = QAction("Reload", self)
        reload_btn.setStatusTip("Reload page")

        reload_btn.triggered.connect(self.browser.reload)
        navtb.addAction(reload_btn)

        home_btn = QAction("Home", self)
        home_btn.setStatusTip("Go home")
        home_btn.triggered.connect(self.navigate_home)
        navtb.addAction(home_btn)

        navtb.addSeparator()

        self.urlbar = QLineEdit()

        self.urlbar.returnPressed.connect(self.navigate_to_url)

        navtb.addWidget(self.urlbar)

        stop_btn = QAction("Stop", self)
        stop_btn.setStatusTip("Stop loading current page")


        stop_btn.triggered.connect(self.browser.stop)
        navtb.addAction(stop_btn)

        self.show()


    def update_title(self):
        title = self.browser.page().title()
        self.setWindowTitle("% s - Not virus" % title)


    def navigate_home(self):

        self.browser.setUrl(QUrl("http://www.google.com"))

    def navigate_to_url(self):


        q = QUrl(self.urlbar.text())


        if q.scheme() == "":

            q.setScheme("http")


        self.browser.setUrl(q)



    def update_urlbar(self, q):

        # setting text to the url bar
        self.urlbar.setText(q.toString())

        # setting cursor position of the url bar
        self.urlbar.setCursorPosition(1)



app = QApplication(sys.argv)


app.setApplicationName("Not virus")

window = MainWindow()

# loop
app.exec_()
David avatar
cn flag
What version of Ubuntu are you using, yes it does matter.
oldfred avatar
cn flag
You are missing a t: QWebEngineWidgets s/b QtWebEngineWidgets
Score:0
pk flag

what makes you decide to install the module directly through pip instead of the python3-pyqt5.qtwebengine package as available via apt?

As David mentioned, the latest Python library version may not compatible with older versions of the Qt5 library, and yes, Ubuntu (mostly) ships older versions, and even older ones depending on the current Ubuntu version you're running.

At least installing the library though apt still guarantees that you're using the right PyQt5 and Qt5 versions available on your Ubuntu version.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.