This is my code. Why its not working? Where is my problem?
JavaScript
x
32
32
1
from PyQt5 import QtCore, QtGui, QtWidgets
2
from PyQt5.Qt import *
3
from PyQt5.QtWebEngineWidgets import *
4
from PyQt5.QtWidgets import QApplication
5
6
7
8
class Ui_Form(object):
9
def setupUi(self, Form):
10
Form.setObjectName("Form")
11
Form.resize(1280, 960)
12
self.widget = QWebEngineView()
13
self.widget.setGeometry(QtCore.QRect(0, 0, 1270, 920))
14
self.widget.setObjectName("widget")
15
self.widget.load(QUrl("google.com"))
16
self.retranslateUi(Form)
17
QtCore.QMetaObject.connectSlotsByName(Form)
18
19
def retranslateUi(self, Form):
20
_translate = QtCore.QCoreApplication.translate
21
Form.setWindowTitle(_translate("Form", "Form"))
22
23
24
if __name__ == "__main__":
25
import sys
26
app = QApplication(sys.argv)
27
Form = QtWidgets.QWidget()
28
ui = Ui_Form()
29
ui.setupUi(Form)
30
Form.show()
31
sys.exit(app.exec_())
32
Advertisement
Answer
Your code has 2 problems:
The QWebEngineView is not a child of the window so it will not be displayed. Change to
self.widget = QWebEngineView(Form)
QUrl("google.com")
is not a valid url so you have 2 options, change to:QUrl("https://google.com")
ORQUrl.fromUserInput("google.com")