PDA

View Full Version : PyQt5 Questions



Miton
17th January 2017, 21:48
Hello,

I've been using PyQt5 for a few applications successfully. However, when trying to set up a web browser, I got the error message "Argument has unexpected type QUrl" on this line.


self.webView.load(self, 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:


import sys
from PyQt5.PyGui 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(self, 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.address Bar.selectAll)
self.goButton.clicked.connect(self.search)
self.goButton.clicked.connect(self.addressBar.sele ctAll)
app = QApplication(sys.argv)
browser = MyBrowser()
browser.show()
sys.exit(app.exec_())



Can anyone help me with these errors or direct me to a site where I can learn what's causing them? I'm not sure how to set up PyQt5 so that it will work again or how to fix the webView function for my computer. Thanks in advance for any help provided.

anda_skoa
18th January 2017, 10:11
Why are you passsing two arguments to load()?

Cheers,
_

Miton
18th January 2017, 18:35
Oops, that line is supposed to have just the url parameter. I tried adding self because the python error said that two parameters were needed, but neither version of the method worked.

anda_skoa
19th January 2017, 11:53
Hmm, QWebView definitely has a load(QUrl) method.

Maybe Python has a problem with the overload? I.e. that in C++ there are two methods with the same name an different arguments?

Cheers,
_

Miton
19th January 2017, 17:05
The error I'm getting in the console window says that the method accepts (self, url). Is there something I can put as the first parameter that might fix things?

anda_skoa
20th January 2017, 10:06
Hmm, "self" would be the webview for a method of the webview, maybe


self.webView.load(self.webview, url)


Cheers,
_

ChrisW67
30th January 2017, 13:10
Line 2 of the code won't get past the Python parser because the module is called PyQt5.QtGui.
Fix that and then


Traceback (most recent call last):
File "code.py", line 3, in <module>
class MyBrowser(QWidget):
NameError: name 'QWidget' is not defined
because you need the PyQt5.QtWidget module. Then


Traceback (most recent call last):
File "code.py", line 35, in <module>
browser = MyBrowser()
File "code.py", line 7, in __init__
self.createLayout()
File "code.py", line 24, in createLayout
self.webView = QWebView()
NameError: name 'QWebView' is not defined
will need PyQt5.QtWebkitWidgets module.