|
发表于 2019-10-21 21:19:41
|
显示全部楼层
import easygui as g
import os
filepath=g.fileopenbox("选择一个文件",'显示文件内容')
with open(filepath) as f:
filedata_old=f.read()
g.textbox('文件['+ os.path.basename(filepath)+']的内容如下:','显示文件内容',filedata_old)
with open(filepath) as f:
filedata_new=f.read()
if filedata_new!=filedata_old:
relust=g.indexbox('检测到文件内容发生了改变,请选择以下操作','警告',('覆盖保存','放弃保存','另存为...'))
if relust==0:
with open(filepath,'w') as f:
f.write(filedata_old)
elif relust==1:
pass
else:
filepath=g.filesavebox('保存为:','显示文件内容',filetypes=['*.txt'])
with open(filepath,'w') as f:
f.write(filedata_old)
|
|