环境:我使用的是wxpythonphoenix 3.0.3和python2.7.10。在
情况:我有一个简单的ProgressDialog,它可以正常工作,只是完成后它不会自动关闭。对话框中有一个关闭按钮,在进程完成之前该按钮处于禁用状态。此时,对话框将等待用户单击“关闭”按钮。在
问题:我想自动关闭它(无需等待用户操作)。在
我尝试过的:对Close()
和{Yield()
来确保所有事件都得到处理,并且尝试了不同时间段的睡眠以确保所有堆叠的事件都得到处理。在
参数:我不想使用线程,这个问题太简单了,我不认为这是问题所在(但如果使用线程提供了一个简单的解决方案,就这样吧)。在
最小工作示例(MWE):
# max progress for progress dialog
max_progress = len(unparsed_files)
progress_dlg = wx.ProgressDialog("Parsing", 'Processing...', max_progress, self,
style=wx.PD_ELAPSED_TIME)
# parse files
for i, uf in enumerate(unparsed_files):
wx.Yield()
progress_dlg.Update(i, 'Processing {}'.format(uf))
self.parse(uf)
progress_dlg.Update(max_progress, 'Parsing completed')
progress_dlg.Destroy()
wx.Yield()
替代解决方案:一个没有按钮的模式对话框,不需要任何用户操作,并且可以有一个wx.Gauge
可以被更新,然后销毁对话框。在
如何关闭并销毁ProgressDialog而不等待用户单击close按钮(或使用没有close按钮的备用对话框)?在
您应该将
wx.PD_AUTO_HIDE
标志添加到style参数中。在来自wxpython的documentation(强调是我的):
相关问题 更多 >
编程相关推荐