如何使用PyQt5在python中打开基于HTML的游戏。?
我有一些基于html和java脚本的网络游戏,想在python的pyqt5窗口中打开它 我曾在tkinter上尝试过,但未能在其中呈现html 需要帮助吗 谢谢。如何使用PyQt5在python中打开基于HTML的游戏。?,python,python-3.x,pyqt5,Python,Python 3.x,Pyqt5,我有一些基于html和java脚本的网络游戏,想在python的pyqt5窗口中打开它 我曾在tkinter上尝试过,但未能在其中呈现html 需要帮助吗 谢谢。 这不使用PyQt5,但可以使用SimpleHTTPServer启动临时web服务器 $ python2 -m SimpleHTTPServer 8000 或 它将提供运行命令的文件夹中的任何内容。这不应该用于生产,因为它只提供最基本的安全检查 一个简单的解决方案是使用软件包中的QWebEngineView 您可以在QWebVi
这不使用PyQt5,但可以使用SimpleHTTPServer启动临时web服务器
$ python2 -m SimpleHTTPServer 8000
或
它将提供运行命令的文件夹中的任何内容。这不应该用于生产,因为它只提供最基本的安全检查
一个简单的解决方案是使用软件包中的QWebEngineView
您可以在
QWebView
中加载页面:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView, QWebEnginePage as QWebPage
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("https://oldgameshelf.com/contra-208.html"))
web.show()
sys.exit(app.exec_())
如果需要滚动到特定元素,可以将JavaScript传递到执行滚动的web.runJavaScript()
在上面的示例中,我使用了您链接到的游戏的OldGameSelf.com链接。但是您可以用任何页面的URL替换它
此外,如果您尚未安装PyQtWebEngine,请确保您已安装:
pip安装PyQtWebEngine
因为现在它被单独包装了。事实上,我在大学时代就尝试过,但没有找到任何帮助,您需要用Python重写整个代码,这是我找到的唯一解决方案。ImportError:无法导入名称'QtWebEngineWidgets'@Akash您必须使用命令安装:
pip3 install PyQtWebEngine
拥有一个脚本文件并在pycharm社区中运行它。我确信。我已经检查了软件包列表,包括pyqt5、PyQtWebEngine、pyqt sipHi eyllanesc。。我可以收到你的电子邮件或whatsapp,这样我就可以和你聊天了。
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
view = QtWebEngineWidgets.QWebEngineView()
url = "https://www.retrogames.cz/play_022-NES.php?language=EN"
view.load(QtCore.QUrl(url))
view.show()
sys.exit(app.exec_())
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView, QWebEnginePage as QWebPage
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("https://oldgameshelf.com/contra-208.html"))
web.show()
sys.exit(app.exec_())