The video at python qt webbrowser no player - python

I've seen the web browser example in Python, it worked fine, but it doesn't play video on the sites I've entered, is there any code that will help
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow,self).__init__(*args, **kwargs)
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://www.google.com"))
self.setCentralWidget(self.browser)
self.show()
app = QApplication(sys.argv)
window = MainWindow()
app.exec_()

Related

Error "Parameter 'url' unfilled" using PyQt5 with url set

import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.browser = QWebEngineView
self.browser.setUrl(QUrl("http://google.com"))
self.setCentralWidget(self.browser)
self.showMaximized()
app = QApplication(sys.argv)
QApplication.setApplicationName('Browser')
window = MainWindow
app.exec_()
This is so far my code, but it gives me an error at the Url line although i've set google.com
You forgot the parenthesis after MainWindow when calling the class at the end, as well as you need to add window.show().
You also need to specify to QWebEngineView an argument (in this case self).
So adding those things the code would look like this:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.browser = QWebEngineView(self)
self.browser.setUrl(QUrl("http://google.com"))
self.setCentralWidget(self.browser)
self.showMaximized()
app = QApplication(sys.argv)
QApplication.setApplicationName('Browser')
window = MainWindow()
window.show()
app.exec_()
Tell me if it doesn't work for you.

QWebEngineView crashes when accessing specific websites

I have a very weird bug with QWebEngineView. Below is some code which creates a QWebEngineView.
import sys
from PyQt5.QtCore import QCoreApplication, QFileInfo, QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings, QWebEngineProfile, QWebEnginePage
class Widget(QWidget):
def __init__(self):
super().__init__()
webview = QWebEngineView(self)
webview.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)
profile = QWebEngineProfile("my_profile", webview)
webpage = QWebEnginePage(profile, webview)
webview.setUrl(QUrl("https://www.youtube.com"))
#self.webview.setPage(self.webpage)
webview.setGeometry(0, 0, 800, 480)
webview.show()
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Widget()
app.exec_()
My issue is that when I run the code as it is (with the self.webview.setPage(self.webpage) line commented out) I am able to open PDF files, however opening YouTube crashes the program. However if I uncomment the line and run it, I can't open PDF files (although it doesn't crash the program it just doesn't open the PDF file), but I can then open YouTube with no issue.
You have to set the QWebEngineProfile and QWebEnginePage first and then enable the plugins:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import (
QWebEnginePage,
QWebEngineProfile,
QWebEngineSettings,
QWebEngineView,
)
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
profile = QWebEngineProfile("my_profile", self)
webpage = QWebEnginePage(profile, self)
webview = QWebEngineView(self)
webview.setPage(webpage)
webview.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)
webview.load(QUrl("https://www.youtube.com"))
lay = QVBoxLayout(self)
lay.addWidget(webview)
self.resize(640, 480)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Widget()
w.show()
app.exec_()

how to configure QLineEdit in pyautogui.typewrite

I use Qtdesigner and then convert it to py file..I want to take input text through the QLineEdit and put it to pyautogui.typewrite. facing problem to solve it.
I write the the code bleow
import pyautogui
import time
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QMovie
from PyQt5.QtCore import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
from messageRHR import Ui_MainWindow
class MainThread(QThread):
def __init__(self,message):
super(MainThread,self).__init__()
# self.message = QLineEdit(self)
def run(self):
self.taskExecution()
def taskExecution(self):
pyautogui.typewrite(message)
time.sleep(1)
pyautogui.press('Enter')
startExecution = MainThread()
class Main(QMainWindow):
def __init__(self):
super(Main, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.startTask)
self.ui.pushButton_2.clicked.connect(self.close)
def startTask(self):
self.ui.movie = QtGui.QMovie("00545cb7179c504433d4c8f5e845f286.gif")
self.ui.label_2.setMovie(self.ui.movie)
self.ui.movie.start()
self.ui.movie = QtGui.QMovie("00545cb7179c504433d4c8f5e845f286.gif")
self.ui.label_3.setMovie(self.ui.movie)
self.ui.movie.start()
message = QLineEdit(self)
startExecution.start()
app = QApplication(sys.argv)
rsn = Main()
rsn.show()
exit(app.exec_())

"Requested OpenGL implementation is not supported. Implementation: 1" error in pyqt5

when i run this code
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow,self).__init__(*args, **kwargs)
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://www.google.com"))
self.setCentralWidget(self.browser)
self.show()
app = QApplication(sys.argv)
window = MainWindow()
app.exec_()
I get this error
[6448:3156:0715/200747.900:ERROR:gl_surface_wgl.cc(399)] Unable to create pbuffer.
[6448:3156:0715/200747.900:ERROR:gl_surface_qt.cpp(197)] Requested OpenGL implementation is not supported. Implementation: 1
what is the cause and solution of this error?
or is there any alternative to QtWebEngineWidgets?
The log points to a problem with opengl so you can change the settings:
# ...
QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
# or
# QCoreApplication.setAttribute(Qt.AA_UseOpenGLES)
app = QApplication(sys.argv)
# ...
See Graphics Drivers for more information

Why should I import QtGui and QtCore in PyQt when it isn't necessary?

I copied a PyQt example from the Web into a file and opened it up in PyCharm. Below is the code:
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from math import *
class Calculator(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.browser = QTextBrowser()
self.expression = QLineEdit()
self.expression.setPlaceholderText("Type an expression and press Enter.")
self.expression.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.expression)
self.someWidget = QWidget()
self.someWidget.setLayout(layout)
self.setCentralWidget(self.someWidget)
self.expression.setFocus()
self.expression.returnPressed.connect(self.updateUi)
self.setWindowTitle("Calculator")
def updateUi(self):
try:
text = self.expression.text()
self.browser.append("%s = %s", (text, eval(text)))
except:
self.browser.append("<font color=red>Invalid Expression</font>")
def main():
import sys
app = QApplication(sys.argv)
window = Calculator()
window.show()
sys.exit(app.exec_())
main()
The problem is that the code run well even without adding the following import statements:
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from math import *
I have seen this example being used in many videos and books. If the code works good without the above statements, then why did the author of the example write the statements.
From PyQt4 to PyQt5, a lot of things moved from QtGui, QtCore to QtWidgets. To write a simple application in PyQt5, you're likely to need only QtWidgets.
My guess is that the code was originally written for PyQt4, and "adapted" to PyQt5, without removing useless imports.
The proper way to import would be import PyQt5.QtWidgets as QtWidgets ( see Should wildcard import be avoided ?).
The code then becomes:
class Calculator(QtWidgets.MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.browser = QtWidgets.QTextBrowser()
self.expression = QtWidgets.QLineEdit()
...

Categories

Resources