【问题标题】:pyqt not responding during reading a filepyqt在读取文件时没有响应
【发布时间】:2020-08-12 12:21:44
【问题描述】:

我使用 PyQt 的 GUI 在我读取方法文件并计算输出时显示没有响应,这将显示在 QWidget 的表中。

因此,读取文件中的行需要几秒钟的时间,我应该为用户找到比“不响应”更好的解决方案。有没有办法绕过它,或者可能是一个等待符号来通知用户它只是在工作。

谢谢各位!

【问题讨论】:

标签: python pyqt qwidget no-response


【解决方案1】:

对于单线程应用程序,不可能同时做两件事:读取文件和处理 GUI。

尝试使用多线程。看看这个:https://docs.python.org/3/library/threading.html
或这个: https://docs.python.org/3/library/_thread.html

还可以查看为https://www.learnpyqt.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/指定的此页面

以及GUI应用多线程StackOverflow的解释: Explanation of need for Multi Threading GUI programming

python中多线程的一个小例子:

def readingAFile(path):
    doSomething()
    showTheDataToGUI()

def main():
    _thread.start_new_thread(readingAFile, (filePath, ))

【讨论】:

    猜你喜欢
    • 2018-05-19
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多