python - 我如何在pyqt中集成一个定时循环

标签 python user-interface pyqt

我正在开发一个 pyqt-gui,它应该有可能在每个选定的时间(例如每 2 分钟)刷新一次数据加载。在这个循环中,gui 应该能够响应事件等。

代码如下所示:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
class TeleModul (QMainWindow):
    def __init__(self, *args):
        QWidget.__init__(self, *args)
        loadUi ("telemodul.ui",self)
        .....
    def on_ButtonSuchen_clicked (self):
        QTimer.singleShot(60000, self.RefreshData())
    def RefreshData(self):
        ...do something ...

点击 ButtonSuchen 引发错误:

TypeError: arguments did not match any overloaded call:
QTimer.singleShot(int, QObject, SLOT()): argument 2 has unexpected type 'NoneType' QTimer.singleShot(int, callable): argument 2 has unexpected type 'NoneType'

问题出在哪里或者整合这个循环的最佳方式是什么?

最佳答案

传递可调用对象,而不是调用它的结果:

QTimer.singleShot(60000, self.RefreshData)

关于python - 我如何在pyqt中集成一个定时循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14120889/

相关文章:

python - 如何开发一个基于 curses 的 UI?

python - Pyqt如何获取小部件的尺寸

python - 使用sparkConf().set设置2个配置值

Python 从 csv 中去掉每一个双引号

python : Import modules once then share with several files

java - 在其他应用程序中使用 Eclipse RCP GUI

flutter - 如何从小部件包装中生成文本?

python - PyQt 本地化 : Translating a text through QPushButton w/use of . po 文件

python - pyqt:向 QFileSystemModel 添加自定义列

python - 当应用程序有多个调用时,日志记录配置无法加载 value-formatter()