This is a simple example with PyQt5 and QWebEngineView.
You can see this example and use it from my GitHub account.
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QPushButton, QMainWindow, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings, QWebEngineView
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.view = QWebEngineView()
lay = QVBoxLayout(self)
lay.addWidget(self.view)
self.resize(640, 480)
class WebEnginePage(QWebEnginePage):
def createWindow(self, _type):
w = Widget()
w.show()
return w.view.page()
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=None)
self.setWindowTitle("PyQt5 ... another example !!")
central_widget = QWidget()
self.setCentralWidget(central_widget)
button = QPushButton('PyQt5 nothing button', self)
button.setToolTip('This is an example button')
self.webview = QWebEngineView()
self.page = WebEnginePage()
self.webview.setPage(self.page)
self.webview.settings().setAttribute(
QWebEngineSettings.FullScreenSupportEnabled, True
)
self.webview.load(
QUrl("https://www.youtube.com/watch?v=BVT3acNFzqc?rel=0&showinfo=0")
)
lay = QVBoxLayout(central_widget)
lay.addWidget(button)
lay.addWidget(self.webview)
def main():
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
if __name__ == "__main__":
main()
pip install unrar
Requirement already satisfied: unrar in c:\python39\lib\site-packages (0.4)
from unrar import rarfile
print("-----------------")
#archiveRARFile = r"C:\\PythonProjects\\RARArchive\\TestRAR.rar"
archiveRARFile = r"C:\\PythonProjects\\RARArchive\\TestRAR001.rar"
extractPath = r"C:\\PythonProjects\\RARArchive"
files = []
#with rarfile.RarFile(archiveRARFile,"r","111") as rarFile:
with rarfile.RarFile(archiveRARFile,"r","") as rarFile:
files = rarFile.namelist()
rarFile.extractall(extractPath)
print("files ",files)
for file in files:
pathFile = fr"{extractPath}+{file}"
with open(file,"r") as f:
data = f.readlines()
for line in data:
line = line.strip()
print(line)
C:\PythonProjects\RARArchive>python unrarFile.py
-----------------
files ['TestRAR.txt']
This is a test for RAR archive.
C:\PythonProjects\RARArchive>python unrarFile.py
-----------------
files ['TestRAR.txt']
This is a test for RAR archive.
http://www.youtube.com/watch_popup?v=VIDEOID
python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
...
import time
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings
from PyQt5.QtWidgets import QApplication
if __name__ == '__main__':
app = QApplication(sys.argv)
webview = QWebEngineView()
profile = QWebEngineProfile("my_profile", webview)
profile.defaultProfile().setPersistentCookiesPolicy(QWebEngineProfile.ForcePersistentCookies)
webpage = QWebEnginePage(profile, webview)
webpage.settings().setAttribute(QWebEngineSettings.PlaybackRequiresUserGesture, False)
webview.setPage(webpage)
webview.load(QUrl("http://www.youtube.com/watch_popup?v=aw4ZDQsFxv0"))
webview.show()
sys.exit(app.exec_())
#!/usr/bin/python
import sys
from PyQt5.QtCore import Qt, QMimeData
from PyQt5.QtGui import QDrag
from PyQt5.QtWidgets import QPushButton, QWidget, QApplication
class Button(QPushButton):
def __init__(self, title, parent):
super().__init__(title, parent)
def mouseMoveEvent(self, e):
if e.buttons() != Qt.RightButton:
return
mimeData = QMimeData()
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())
dropAction = drag.exec_(Qt.MoveAction)
def mousePressEvent(self, e):
super().mousePressEvent(e)
if e.button() == Qt.LeftButton:
print('press')
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setAcceptDrops(True)
self.button = Button('Button', self)
self.button.move(100, 65)
self.setWindowTitle('Drag and drop with mouse - right click to move Button!')
self.setGeometry(300, 300, 550, 450)
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
position = e.pos()
self.button.move(position)
e.setDropAction(Qt.MoveAction)
e.accept()
def main():
app = QApplication(sys.argv)
ex = Example()
ex.show()
app.exec_()
if __name__ == '__main__':
main()
import sys, os
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
class ImageLabel(QLabel):
def __init__(self):
super().__init__()
self.setAlignment(Qt.AlignCenter)
self.setText('\n\n Drop Image Here \n\n')
self.setStyleSheet('''
QLabel{
border: 3px dashed #bbb
}
''')
def setPixmap(self, image):
super().setPixmap(image)
class AppDemo(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Drag and drop one image to this window!')
self.setGeometry(300, 300, 550, 450)
self.setAcceptDrops(True)
mainLayout = QVBoxLayout()
self.photoViewer = ImageLabel()
mainLayout.addWidget(self.photoViewer)
self.setLayout(mainLayout)
def dragEnterEvent(self, event):
if event.mimeData().hasImage:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasImage:
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasImage:
event.setDropAction(Qt.CopyAction)
file_path = event.mimeData().urls()[0].toLocalFile()
self.set_image(file_path)
event.accept()
else:
event.ignore()
def set_image(self, file_path):
self.photoViewer.setPixmap(QPixmap(file_path))
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
sys.exit(app.exec_())
C:\Python310>python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
...
SyntaxError: '{' was never closed
...
>>> foo(a, b for b in range(5), c)
...
foo(a, b for b in range(5), c)
^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
...
>>> {a, b for (a, b) in zip("a", "b")}
...
{a, b for (a, b) in zip("a", "b")}
^^^^
SyntaxError: did you forget parentheses around the comprehension target?
...
SyntaxError: expected ':'
...
SyntaxError: invalid syntax. Perhaps you forgot a comma?
...
SyntaxError: ':' expected after dictionary key
...
SyntaxError: expected 'except' or 'finally' block
...
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
...
IndentationError: expected an indented block after 'if' statement in line ...
...
>>> import collections
>>> collections.namedtoplo
...
AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: 'namedtuple'?
...
>>> a = 0
>>> aa
...
NameError: name 'aa' is not defined. Did you mean: 'a'?
$ pip install pyqt5