Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5 Question
#1
Hello,

I've been trying to learn Qt through tutorials. However, when trying to follow tutorials on making web browsers, I got the error message "Argument has unexpected type QUrl" on this line.

Qt Code:

self.webView.load(url) 

One of the ways I tried to fix this was by reinstalling PyQt5. After doing so I started getting the error message "ImportError: No Module named 'PyQt5.PyGui
instead. I've tried reinstalling Anaconda, replacing PyQt5 with version 5.6, and switching the tutorial's opening line to "From PyQt5 import *", which leads to the error "NameError: name QWidget is not defined". I'm using Python 3.5 on Windows 7 64-bit. Here's the tutorial I'm trying to follow:

Qt Code:


import sys
from PyQt5 import *

class MyBrowser(QWidget):

    def __init__(self, parent = None):
        super(MyBrowser, self).__init__(parent)
        self.createLayout()
        self.createConnection()

    def search(self):
        address = str(self.addressBar.text())
        if address:
            if address.find('://') == -1:
                address = 'http://' + address
            url = QUrl(address)
            kwargs = {}
            self.webView.load(url)

    def createLayout(self):
        self.setWindowTitle("keakon's browser")
        self.addressBar = QLineEdit()
        self.goButton = QPushButton("&GO")
        bl = QHBoxLayout()
        bl.addWidget(self.addressBar)
        bl.addWidget(self.goButton)
        self.webView = QWebView()
        layout = QVBoxLayout()
        layout.addLayout(bl)
        layout.addWidget(self.webView)
        self.setLayout(layout)

    def createConnection(self):
        self.addressBar.returnPressed.connect(self.search)
        self.addressBar.returnPressed.connect(self.addressBar.selectAll)
        self.goButton.clicked.connect(self.search)
        self.goButton.clicked.connect(self.addressBar.selectAll)

app = QApplication(sys.argv)
browser = MyBrowser()
browser.show()
sys.exit(app.exec_())

Can anyone help me with these errors or direct me to a resource where I can learn what's causing them? I'm not sure how to set up PyQt5 so that it will work again or whether the PyQt5 webkit works at all on windows. Thanks in advance for any help provided.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package" chipx 3 7,419 Dec-09-2021, 07:05 AM
Last Post: chipx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020