javascript - 我可以在 PyQt5 QWebEngine 中将 Python 连接到 JavaScript 吗?
问题描述
我已经设置了一个基本的 PyQt5 GUI 窗口,中间有一个 QWebEngine 网络浏览器元素,我想要一个很好的方法来设置以下内容:
我希望网络浏览器显示一个本地 HTML 文件,当你按下页面上的某个按钮时,它会调用一个 python 函数,该函数会依次更新 html 中的一些内容。
这就是我到目前为止所得到的;我尝试了很多不同的方法,但它们似乎都是针对 PyQt4 而不是使用 QWebEngine。
import sys, os
import PyQt5
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
class WindowC(PyQt5.QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(WindowC,self).__init__(*args, **kwargs)
self.directory = os.getcwd()
self.browser = QWebEngineView()
self.setCentralWidget(self.browser)
local_url = QUrl.fromLocalFile( os.path.join( self.directory, "page.html" ) )
self.browser.load(local_url)
app = PyQt5.QtWidgets.QApplication(sys.argv)
window = WindowC()
window.show()
app.exec_()
对不起,如果问题有点模糊
解决方案
推荐阅读
- sql - Oracle 错误 (36,14): PL/SQL: ORA-22905: 无法访问非嵌套表项中的行
- android - 不兼容的类型:getFragmentManager 不起作用
- security - bcrypt 次要版本会生成(2b 与 2a)生成不同的盐吗?
- google-apps-script - 在应用程序制造商中为下拉列表和单选组选择默认值
- java - 无法设置 java web 服务来显示 SQL Server 数据
- xwiki - Xwiki 数据传输(两页之间)
- ms-access - mysql访问数据库-图片展示
- android - 在 android studio gradle 文件中全局设置 lintOptions
- jquery - 让 jQuery dataTables 响应不同的窗口大小
- vba - 如何删除修改字符串以从新工作表中删除字母