Search code examples
pythonpyqtqwidgetno-response

pyqt not responding during reading a file


my GUI with PyQt is showing not responding during I´m reading in a method a file and calculating an Output, which will shown in the table of the QWidget.

Thus it takes some seconds for reading the lines in the file and I should find a better solution for the user than the "not responding". Is there a way to get around it or Maybe a waiting Symbol to inform the user it´s just working.

Thanks guys!


Solution

  • For a single-Thread application, it would be impossible to do two things together: reading a file and handling the GUI.

    Try to use multi-threading. Have a look of this: https://docs.python.org/3/library/threading.html
    or this: https://docs.python.org/3/library/_thread.html

    Also have a look of this page specified for https://www.learnpyqt.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/

    And an explanation on StackOverflow of multi-threading of GUI application: Explanation of need for Multi Threading GUI programming

    A small example for multi-threading in python:

    def readingAFile(path):
        doSomething()
        showTheDataToGUI()
    
    def main():
        _thread.start_new_thread(readingAFile, (filePath, ))