pyton easygui 确定和取消问题
本帖最后由 xiangya 于 2020-7-17 09:50 编辑自己做了小EXe,可以运行,点击OK 按钮没有问题,但是点取消的时候会出现错误提示(failed to execute script),有没有办法解决。
还有点击OK 后能不能让窗口保持不关闭?
求大佬解答{:5_96:}
发代码 qiuyouzhi 发表于 2020-7-17 09:52
发代码
刚开始学,照着网上拼凑的,{:5_96:}
import os
import easygui as a
# -*- coding: utf-8 -*-
class SearchFile(object):
def findfile(self, keyword, workpath):
filelist = []# 文件路径
filelist_ones = []# 绝对路径
file_qjs = []# 清机
file_xfs = []# 信封
file_cks = []# 存款
file_gzs = []# 故障
file_xlhs = []# 序列号
for workpath, dirs, files in os.walk(workpath):
for name in files:
fitfile = filelist.append(os.path.join(workpath, name))
# print(fitfile)
# print(os.path.join(workpath, name))
# print(filelist)
# print('...........................................')
for i in filelist:
if os.path.isfile(i):
# print(i)
if keyword in os.path.split(i):
# print(i) # 绝对路径
filelist_one = filelist_ones.append(i)
# else:
# print('......no keyword!')
# print(filelist_ones)
# print('...........................................')
for filelist_one in filelist_ones:
with open(filelist_one, 'r', encoding='utf-8') as f_obj:
# print("清机信息")
for line in f_obj:
if '清机:' in line:# 查找清机日志行
# print(line)
file_qj = file_qjs.append(line)
elif 'totalAmount:' in line:# 查找现金存款日志行
file_ck = file_cks.append(line)
elif '手输金额:' in line:# 查找信封日志行
# print(line)
file_xf = file_xfs.append(line)
elif '机芯故障代码:' in line:# 查找机芯故障日志行
# print(line)
file_gz = file_gzs.append(line)
elif '设备序列号:' in line:# 查找设备序列号
file_xlh = file_xlhs.append(line[-9:])
print("设备序列号:"+file_xlhs)
print("清机信息")
for file_qj in file_qjs:
print(file_qj)
print('...........................................')
print("故障信息")
for file_gz in file_gzs:
print(file_gz)
print('...........................................')
print('现金存款')
for file_ck in file_cks:
print(file_ck)
print('...........................................')
print('信封存款')
for file_xf in file_xfs:
print(file_xf)
print('...........................................')
filename = '分析结果.txt'
with open(filename, 'w', encoding='utf-8') as file_ob:
file_ob.write("设备序列号:"+file_xlhs+'\n')
file_ob.write('清机信息:' + '\n')
for len_1 in range(len(file_qjs)):
# ss =str(file_gzs).replace('[','').replace(']','')
qj = str(file_qjs).replace(',', '') + '\n'
file_ob.write(qj)
file_ob.write('故障信息:' + '\n')
for len_2 in range(len(file_gzs)):
gz = str(file_gzs).replace(',', '') + '\n'
file_ob.write(gz)
file_ob.write('现金存款:' + '\n')
for len_3 in range(len(file_cks)):
ck = str(file_cks).replace(',', '') + '\n'
file_ob.write(ck)
file_ob.write('信封存款:' + '\n')
for len_4 in range(len(file_xfs)):
xf = str(file_xfs).replace(',', '') + '\n'
file_ob.write(xf)
file_ob.close()
def __call__(self):
while True:
workpath = ret
if (workpath == ''):
break
# if workpath=='y' or workpath=='Y':
# root=self.abspath # 把当前工作目录作为工作目录
# print('当前工作目录:',root)
# dirlist=os.listdir()# 列出工作目录下的文件和目录
# print(dirlist)
else:
# root=input('please enter the working directory:')
print('当前工作目录:', workpath)
# keyword=input('the keyword you want to find:')
# if(keyword==''):
# break
self.findfile('XZ_JS', workpath)# 查找带指定字符的文件
break
ret = a.enterbox(msg='请输入文件路径', title='日志处理', strip=True)
print(ret)
if __name__ == '__main__':
search = SearchFile()
search()
xiangya 发表于 2020-7-17 09:55
刚开始学,照着网上拼凑的,
import os
ret = a.enterbox(msg='请输入文件路径', title='日志处理', strip=True)
print(ret)
if ret != None:
if __name__ == '__main__':
search = SearchFile()
search()
加一句if判断,如果ret为None时不运行程序,既用户没输入文件路径时或者直接关闭时,就没必要运行主程序了。你也可以加个msg窗口,提示用户。 yhhpf 发表于 2020-7-17 10:38
加一句if判断,如果ret为None时不运行程序,既用户没输入文件路径时或者直接关闭时,就没必要运行主程 ...
嗯,谢谢大佬,弹窗没了。
那点击Ok后可不可以不关闭程序,网上找了几圈没看见 xiangya 发表于 2020-7-17 11:31
嗯,谢谢大佬,弹窗没了。
那点击Ok后可不可以不关闭程序,网上找了几圈没看见
while True:
ret = a.enterbox(msg='请输入文件路径', title='日志处理', strip=True)
print(ret)
if ret != None:
if __name__ == '__main__':
search = SearchFile()
search()
else:
break
加上个循环就好了
如果问题已解决,记得给个最佳哦~~~{:10_256:}
yhhpf 发表于 2020-7-17 11:40
加上个循环就好了
如果问题已解决,记得给个最佳哦~~~
感谢!搞定{:5_95:}
页:
[1]