python - pyqt如何显示实时数据
天蓬老师
天蓬老师 2017-04-17 17:48:08
0
2
1021

我有一个处理example.csv的后台程序,现在想把当前读行数实时显示到GUI界面中去。
就是这下面

能否提供一些思路,谢谢!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
洪涛

Isn’t that what PyQt’s signal-slot mechanism does? The input box you want to input, such as LineEdit, corresponds to a slot. A signal is sent to the processing place, and PyQt does the binding itself without any specific function calls. , the code looks much cleaner
In the example below, BackendThread simulates the background thread. After the data is processed, it is updated to the foreground and refreshed every second. Just replace it with your own logic

# -*- coding: utf-8 -*-

from PyQt4.Qt import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time


class Backend(QThread):
    update_date = pyqtSignal(QString)
    def run(self):
        while True:
            data = QDateTime.currentDateTime()
            self.update_date.emit(QString(str(data)))
            time.sleep(1)


class Window(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.resize(400, 100)
        self.input = QLineEdit(self)
        self.input.resize(400, 100)

    def handleDisplay(self, data):
        self.input.setText(data)


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    b = Backend()
    w = Window()
    b.update_date.connect(w.handleDisplay)
    b.start()
    w.show()
    app.exec_()
伊谢尔伦

Define a global variable and write the current line number into the variable when reading
The scheduled program regularly updates the value on the interface (take the global variable)

This is the simplest and crudest way

Another one, execute asynchronously when reading, directly update the number of rows to the interface

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!