web_browser.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'web_browser.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(779, 257)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
web_browser_main.py
from web_browser import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QUrl
from PyQt5.QtWebKitWidgets import QWebView , QWebPage
import sys
class TestBrowserCode:
def __init__(self):
self.app = QtWidgets.QApplication(sys.argv)
self.mainWindow = QtWidgets.QMainWindow()
self.main_ui = Ui_MainWindow()
self.main_ui.setupUi(self.mainWindow)
self.mainWindow.showMaximized()
self.open_google()
sys.exit(self.app.exec_())
def open_google(self):
self.google_url = 'http://www.google.com'
self.main_ui.chat_browser = QWebView()
self.main_ui.chat_page = QWebPage()
self.main_ui.chat_browser.setPage(self.main_ui.chat_page)
self.main_ui.chat_browser.setUrl(QUrl(self.google_url))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.main_ui.chat_browser.setMinimumSize(QtCore.QSize(0, 398))
self.main_ui.chat_browser.setMaximumSize(QtCore.QSize(16777215, 398))
self.main_ui.chat_browser.setSizePolicy(sizePolicy)
self.main_ui.chat_browser.setStyleSheet("background-color:white;border:1px solid #dadada;")
self.main_ui.verticalLayout.addWidget(self.main_ui.chat_browser)
self.main_ui.chat_browser.show()
program = TestBrowserCode()
- Run the code from source:
Χρήστος@Chris-pc MINGW64 /c/python/scripts/Papinhio player/notes $ python web_browser_main.py
(The site is displayed correct)
- Make an .exe file (full result here)
Traceback (most recent call last):
File "C:/Python/Scripts/Papinhio player/notes/web_browser_main.py", line 4, in
from PyQt5.QtWebKitWidgets import QWebView , QWebPage
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 657, in _load_unlocked
File "", line 556, in module_from_spec
File "", line 1101, in create_module
File "", line 219, in _call_with_frames_removed
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
[17208] Failed to execute script web_browser_main
Result error import PyQt5.QtWebKitWidgets
All that inside msys2 mingw64 console. How can I compile the above files?