youtube视频嵌入pyqt

编程入门 行业动态 更新时间:2024-10-14 00:26:14
本文介绍了youtube视频嵌入pyqt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

DirectShowService:doRender 未解决的错误代码

from PyQt5 import QtWidgets,QtCore,QtGui导入系统,时间从 PyQt5.QtCore 导入 Qt,QUrl从 PyQt5 导入 QtWebKit从 PyQt5 导入 QtWebKitWidgets从 PyQt5.QtWebKit 导入 QWebSettings#from PyQt5 import QtWebEngineWidgets #import QWebEngineView,QWebEngineSettings类窗口(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("www.youtube/watch?v=Mq4AbdNsFVw"))self.vlayout.addWidget(self.webview)self.centralwid.setLayout(self.vlayout)self.setCentralWidget(self.centralwid)自我展示()app=QtWidgets.QApplication([])前=窗口()sys.exit(app.exec_())

解决方案

您正在从 PyQt5 (

How Can I embed youtube video using PyQt5? I tried doing the following,but it gave me an unresolved error:

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("www.youtube/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_())

解决方案

You are importing some deprecated modules from PyQt5 (QtWebKit, and QtWebKitWidgets). It seems you have the right paths commented out at the bottom of your imports.

If you resolve these issues and use the proper modules (QtWebEngineCore, QtWebEngineWidgets) it works on my system.

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("www.youtube/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_())

The output I get looks like the following (which seems correct):

更多推荐

youtube视频嵌入pyqt

本文发布于:2023-11-05 18:37:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   youtube   pyqt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!