gpt4 book ai didi

python - youtube视频嵌入pyqt

转载 作者:太空宇宙 更新时间:2023-11-04 02:35:07 33 4
gpt4 key购买 nike

如何使用 PyQt5 嵌入 youtube 视频?我尝试执行以下操作,但它给了我一个 Unresolved 错误:

DirectShowService:doRender unresolved error code

from PyQt5 import QtWidgets,QtCore,QtGui
import sys, time
from PyQt5.QtCore import Qt,QUrl
from PyQt5 import QtWebKit
from PyQt5 import QtWebKitWidgets
from PyQt5.QtWebKit import QWebSettings
#from PyQt5 import QtWebEngineWidgets #import QWebEngineView,QWebEngineSettings

class window(QtWidgets.QMainWindow):
def __init__(self):
QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled,True)
super(window,self).__init__()
self.centralwid=QtWidgets.QWidget(self)
self.vlayout=QtWidgets.QVBoxLayout()
self.webview=QtWebKitWidgets.QWebView()
self.webview.setUrl(QUrl("https://www.youtube.com/watch?v=Mq4AbdNsFVw"))
self.vlayout.addWidget(self.webview)
self.centralwid.setLayout(self.vlayout)
self.setCentralWidget(self.centralwid)
self.show()

app=QtWidgets.QApplication([])
ex=window()
sys.exit(app.exec_())

最佳答案

您正在从 PyQt5(QtWebKitQtWebKitWidgets)导入一些已弃用的模块。您似乎在导入的底部注释掉了正确的路径。

如果您解决了这些问题并使用了正确的模块(QtWebEngineCoreQtWebEngineWidgets),它就可以在我的系统上运行。

from PyQt5 import QtWidgets,QtCore,QtGui
import sys, time
from PyQt5.QtCore import Qt,QUrl
from PyQt5 import QtWebEngineWidgets
from PyQt5 import QtWebEngineCore
from PyQt5.QtWebEngineWidgets import QWebEngineSettings

class window(QtWidgets.QMainWindow):
def __init__(self):
QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.PluginsEnabled,True)
super(window,self).__init__()
self.centralwid=QtWidgets.QWidget(self)
self.vlayout=QtWidgets.QVBoxLayout()
self.webview=QtWebEngineWidgets.QWebEngineView()
self.webview.setUrl(QUrl("https://www.youtube.com/watch?v=Mq4AbdNsFVw"))
self.vlayout.addWidget(self.webview)
self.centralwid.setLayout(self.vlayout)
self.setCentralWidget(self.centralwid)
self.show()

app=QtWidgets.QApplication([])
ex=window()
sys.exit(app.exec_())

我得到的输出如下所示(看起来是正确的):

enter image description here

关于python - youtube视频嵌入pyqt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48103685/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com