How to run a video inside a GUI

Asked

Viewed 196 times

0

good evening, I’m having a problem. I need to run a youtube video inside a GUI interface (with Python).

A community user helped me by providing the following code:

https://gist.github.com/rodgomesc/2c6d85f85ac0cc28a3d5

however, it was written using pyqt4. But all my final project is done in python version 3.

Someone would know how to do the same using Pyqt5 or if I can install Pyqt4 in python version 3 (I’ve tried a lot).

Note: ideas with other modules are also very welcome.

  • Dude, the Qwebview class, which is the most important one in this case, also exists in Pyqt5. Try to update Imports.

1 answer

1

So, the only thing that comes to mind is to use a widget that renders html properly, exactly as is proposed in the code you posted.

Making some modifications, I managed to get a very similar result on GNU/Linux:

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView


app = QApplication(sys.argv)
web = QWebEngineView()

html = '<!doctype html><html><head></head><body><iframe width="560" height="315" src="https://www.youtube.com/embed/zqFPTkxu-Rc" frameborder="0" allowfullscreen></iframe></body></html>'
url = QUrl("https://www.youtube.com/")  
web.setHtml(html, url)

web.show()
app.exec()

The difference is that in version 5, there is no longer the Qstring class, so you can use standard Python strings instead.

Also, instead of using the widget QWebView, I used the QWebEngineView which, according to the documentation, replaces Qwebkit for more current HTML, CSS and Javascript support. However, according to the same source, you may have problems using this widget in windows.

If this is your case, you might want to switch libraries. The wxPython has html support, just do not know how is their support for Python 3. Besides it, you can take a look at GTK+, that also has a Webkit that can solve your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.