Home  >  Q&A  >  body text

python - pyqt如何显示实时数据

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

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

天蓬老师天蓬老师2742 days ago1027

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:50:08

    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_()

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:50:08

    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

    reply
    0
  • Cancelreply