python qtpy只显示白色屏幕,即使我运行简单的代码

rsl1atfo  于 2023-04-19  发布在  Python
关注(0)|答案(1)|浏览(508)

这不是我的主程序,但即使这样的结果在空白的白色屏幕

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *

app = QApplication([])

window = QMainWindow()
window.setWindowTitle('My Browser')

view = QWebEngineView()
window.setCentralWidget(view)

view.setUrl(QUrl('https://www.google.com'))

window.show()

app.exec_()
c2e8gylq

c2e8gylq1#

添加下面一行即可修复

view.show()

view.show()是一个方法,用于在屏幕上显示QWebEngineView小部件。

您的固定编码为
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *

app = QApplication([])
window = QMainWindow()
window.setWindowTitle('My Browser')

view = QWebEngineView()
window.setCentralWidget(view)
view.show()  #import

view.setUrl(QUrl('https://www.google.com'))
window.show()
app.exec_()

相关问题