我正在创建一个GUI,在那里我想用qWebView显示一个站点,并每隔10秒自动重新加载它。你知道吗
我尝试了一个qThread,没有结果。(我是一个新的线程) 如果我使用正常的while循环,我的窗口就会冻结。你知道吗
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
class updator(QtCore.QThread):
def __init__(self, window):
QtCore.QThread.__init__(self)
def run(self):
while True:
self.sleep(2000 * 2 / 1000)
self.window.htmlreader_BTCLiveGraph.reload()
class Ui_BTC_LiveGraph(object):
def setupUi(self, BTC_LiveGraph):
BTC_LiveGraph.setObjectName("BTC_LiveGraph")
BTC_LiveGraph.resize(1600, 900)
BTC_LiveGraph.setAccessibleDescription("")
self.htmlreader_BTCLiveGraph = QtWebEngineWidgets.QWebEngineView(
BTC_LiveGraph)
self.htmlreader_BTCLiveGraph.setGeometry(
QtCore.QRect(10, 10, 1500, 800))
self.htmlreader_BTCLiveGraph.setAccessibleDescription("")
# récupération du chemin absolu du fichier
self.mypath = os.path.dirname(__file__)
self.htmlreader_BTCLiveGraph.setUrl(QtCore.QUrl(
str("file:///" + self.mypath + "/BTC_liveGraph.html")))
self.htmlreader_BTCLiveGraph.setObjectName("htmlreader_BTCLiveGraph")
self.retranslateUi(BTC_LiveGraph)
QtCore.QMetaObject.connectSlotsByName(BTC_LiveGraph)
def retranslateUi(self, BTC_LiveGraph):
_translate = QtCore.QCoreApplication.translate
BTC_LiveGraph.setWindowTitle(
_translate("BTC_LiveGraph", "BTC Live Graph"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
BTC_LiveGraph = QtWidgets.QDialog()
ui = Ui_BTC_LiveGraph()
ui.setupUi(BTC_LiveGraph)
BTC_LiveGraph.show()
update = updator(ui)
update.start()
sys.exit(app.exec_())
我希望qwebviewWidget每10秒重新加载一次,并且没有冻结窗口
我认为
QTimer
是解决这个问题的更好方法,下面是一个工作示例:相关问题 更多 >
编程相关推荐