【发布时间】:2015-07-15 11:28:10
【问题描述】:
我如何评估用户是否按下了
Close Window按钮wx.fileDialog打开文件时?
我有 2 个文本框... 一个用于显示输入文件路径 另一个是显示输出文件路径
output 依赖于input filepath,因为output filepath 将与输入的目录相同,但名称不同。
有时用户opens the filepath and press the close button...
并且该操作会生成一个等于_edited.txt 的outfile,但这不应该发生。
我想要类似的东西
if user_action == press_the_close_button:
outfile = ""
else:
outfile = infile_edited.txt
我该如何解决?
我正在使用: Py 2.7.9 和 wx 3.0.2.0
openFile 函数
def abrirArquivo(self, event):
try:
#open fileDialog box
openFileDialog = wx.FileDialog(self, "Open", "", "", "Text files (*.txt)|*.txt", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
openFileDialog.ShowModal()
#get the filepath
infile = openFileDialog.GetPath()
#change the inputTxtCtrl to the filepath
self.inputTxtCtrl.SetValue(infile)
#if user dont select any file in the fileDialog, how can i evaluate it and correctly so it doesnt change the outfileTextBox
if infile == "":
#change textLabel to "File not selected.."
self.textoProgresso.SetLabel("File wasn't loaded properly...")
else:
#create output filepath
outfile = infile[0:len(str(infile))-4] + "_edited.txt"
#change outputTxtCtrl to the outfile filepath
self.outputTxtCtrl.SetValue(outfile)
#change progress bar to 10%
self.barraProgresso.SetValue(10)
#change textLabel to "File found.."
self.textoProgresso.SetLabel("File loaded in the system...")
except Exception:
print "error_abrir_arquivo"
【问题讨论】:
标签: python python-2.7 wxpython wxwidgets