Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
现在我正在使用 Python 循环复制大量文件。复制时,我告诉 PyQt 将反馈附加到 QTextEdit:
for src in sources: shutil.copy(src, dst) self.feedback.append("Copying " + src)
(self.feedback是 QTextEdit)。
self.feedback
当我启动我的脚本时,PyQt 会冻结,直到所有副本都完成,然后才一次显示所有内容。
如何在复制文件时实时显示每个反馈?
由于您的任务完全受 IO 限制,您可以简单地告诉 Qt 在开始下一个复制操作之前处理任何待处理的 gui 事件:
for src in sources: self.feedback.append('Copying: %s' % src) QtGui.qApp.processEvents() shutil.copy(src, dst)