import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.browser = QWebEngineView self.browser.setUrl(QUrl("http://google.com")) self.setCentralWidget(self.browser) self.showMaximized() app = QApplication(sys.argv) QApplication.setApplicationName('Browser') window = MainWindow app.exec_()
This is so far my code, but it gives me an error at the Url line although i’ve set google.com
Advertisement
Answer
You forgot the parenthesis after MainWindow when calling the class at the end, as well as you need to add window.show(). You also need to specify to QWebEngineView an argument (in this case self).
So adding those things the code would look like this:
import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.browser = QWebEngineView(self) self.browser.setUrl(QUrl("http://google.com")) self.setCentralWidget(self.browser) self.showMaximized() app = QApplication(sys.argv) QApplication.setApplicationName('Browser') window = MainWindow() window.show() app.exec_()
Tell me if it doesn’t work for you.