我有一个Python应用程序,它有一个可以手动更改的wx.dirPicker控件,在运行我的代码之前,我需要确保选择的路径存在。为了做到这一点,我使用以下代码:
def m_dirPicker1OnUpdateUI( self, event ):
src_directory = self.m_dirPicker1.GetTextCtrlValue()
if os.path.exists(src_directory)==False:
dlg = wx.MessageDialog( self, "The specified path doesn't exist", "Warning", wx.ICON_ERROR | wx.ICON_EXCLAMATION )
dlg.ShowModal()
#print(dlg.GetReturnCode())
if dlg.GetReturnCode() == 0:
self.Destroy() 它可以很好地检测路径是否存在。
但是,当路径不存在时,消息对话框出现,但我无法在按下OK按钮后将其关闭,并且我不明白为什么。
谢谢。
发布于 2013-02-07 23:58:09
我的第一种方法是:每次有人手动更改wx.dirpicker路径时,我都需要确保该路径存在,因为我的应用程序会将一个报告文件导出到该路径。
后来,我决定只在有人按下“创建报告”按钮时才检查路径。为此,我使用以下代码:
try:
if src_directory = self.m_dirPicker1.GetTextCtrlValue():
if os.path.exists(src_directory)==False:
dlg = wx.MessageDialog( self, "The specified path doesn't exist", "Warning", wx.ICON_EXCLAMATION)
dlg.ShowModal()
else:
#run my code to create report file in src_directory path
except:
create report_error file 发布于 2013-02-06 00:00:01
我认为你应该在“self.Destroy()”之前调用"dlg.Destroy()“:
result = dlg.ShowModal()
dlg.Destroy()
if result == 0:
self.Destroy() https://stackoverflow.com/questions/14710919
复制相似问题