销毁时强制ProgressDialog关闭

2024-09-27 07:21:29 发布

您现在位置:Python中文网/ 问答频道 /正文

环境:我使用的是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按钮的备用对话框)?在


Tags: 用户for事件files解决方案线程按钮max
1条回答
网友
1楼 · 发布于 2024-09-27 07:21:29

您应该将wx.PD_AUTO_HIDE标志添加到style参数中。在

来自wxpython的documentation强调是我的):

Causes the progress dialog to disappear from screen as soon as the maximum value of the progress meter has been reached. If this style is not present, the dialog will become a modal dialog once the maximum value has been reached and wait for the user to dismiss it.

相关问题 更多 >

    热门问题