【发布时间】:2022-11-04 21:11:44
【问题描述】:
最近我一直在用 PySide6 (Qt) 为我的 python 脚本构建一个 GUI。我添加了一个按钮,在按下时执行我的脚本:
def button_start_collecting(self):
if not self.input_src.text():
self.log_message("Please add the missing source path")
if not self.input_dest.text():
self.log_message("Please add the missing destination path")
else:
self.log_message("Starting to collect...")
execute_pvt(self.dest, self.origin)
self.log_message("The files and directories have been collected")
我的问题是,我希望在脚本本身执行之前日志消息出现在我的日志小部件上,但它没有显示出来。只有在执行完成后,两条日志消息才会同时出现。就好像代码的结构如下:
else:
execute_pvt(self.dest, self.origin)
self.log_message("Starting to collect...")
self.log_message("The files and directories have been collected")
有人知道如何解决这个问题吗?
【问题讨论】:
-
如果预计没有其他 UI 元素与用户交互,并且在
execute_pvt中完成的操作不会花费太多时间,请在第一个log_message之后立即调用QApplication.processEvents()。否则,请为此使用 threading/QThread。